mercredi 4 mars 2015

Java program goes into if statement where it shouldnt [duplicate]


This question already has an answer here:




So I am new to java and tried this



start=input.next();

if (start != "ja" && start != "nein") {
while (start != "ja" && start != "nein") {
System.out.println("Nur ja oder nein eingeben.");
start=input.next();
}
}
if(start=="ja"){
playing=true;
}
else{
playing=false;
}


But in the next line where I wrote



while(playing){...}


It compiles fine, but when I enter "ja" or "nein" it goes into the if statement rather than skipping it, what did I do wrong there?


Aucun commentaire:

Enregistrer un commentaire