我正在尝试做一个 while 循环,如果密码正确,则打印欢迎语句,如果您错了,则拒绝您。当你错了,我希望它重新提出问题。不幸的是,当密码错误时,它只会发送垃圾邮件并且不会重新循环。谢谢!
import java.util.Scanner;
public class Review {
public static void main(String[] args) {
Scanner userInput = new Scanner(System. in );
System.out.println("Enter user password");
String userGuess = userInput.nextLine();
int x = 10;
while (x == 10) {
if (userGuess.equals("test")) {
System.out.println("Welcome");
return;
} else if (!userGuess.equals("test")) {
System.out.println("Wrong, try again");
break;
}
}
}
}