只要String Inputconfirmed未设置为" ja"我的while循环应该运行。在循环的底部。然而不知何故,即使在" ja"进入。 我的下面的代码,我将非常感谢我在这里做错了什么。 请注意我已经使用.equals和.equalsIgnoreCase而不是.contains。提前谢谢。
String Inputconfirmed = "nee";
while(!Inputconfirmed.contains("ja")){
System.out.println("\nHallo daar, welkom bij SPOOKTOCHT!\n"+
"\nWat is je voornaam?"+
"\n(Typ je naam en druk op 'ENTER')");
String Firstname = scan.nextLine();
System.out.println("Hoi "+Firstname+"!"+
"\nWat is je achternaam?");
String Lastname = scan.nextLine();
System.out.println("Bedankt! En hoe oud is "+Firstname+" "+Lastname+"?");
int Age = 0;
while(Age < 1 || Age > 99){
try{Age = scan.nextInt();
} catch (InputMismatchException e){
System.out.println("Je mag hier alleen een cijfer invoeren van 1 tot 99."+
"\nProbeer het nog eens.");
scan.nextLine();
}
}
Character Player = new Character();
Player.setFirstname(Firstname);
Player.setLastname(Lastname);
Player.setAge(Age);
System.out.println("Dus jij bent: "+Player.getFirstname()+" "+Player.getLastname()+" en je bent "+Player.getAge()+" jaar oud."+
"\nKlopt dit?");
Inputconfirmed = scan.nextLine();
scan.nextLine();
}