我试图在地址中输入错误的内容以重复“您住在哪里?”的问题 使用 while 方法,但它似乎不再起作用了。
import java.util.Scanner;
public class ImScrewed {
public static void main(String[] args) {
boolean flag = true;
Scanner scan = new Scanner(System.in);
while (flag) {
System.out.println("== Welcome to UwU Cafe! ==");
System.out.print("What is your name? [Starts with 'Mr. ' or 'Ms. '] : ");
String name = scan.nextLine();
if (name.startsWith("Ms. ") || name.startsWith("Mr. ")) {
System.out.println("Welcome : " + name);
flag = false;
} else {
System.out.println("Please re-enter your name");
}
}
System.out.println("Where do you live? [Contains 'Street']");
String address = scan.nextLine();
if (address.contains("Street")) {
System.out.println("Proceed to the next step");
flag = false;
} else {
System.out.println("Please re-enter your address");
}
}
}
繁花不似锦
相关分类