mercredi 22 juillet 2015

Why does the scanner gets te wrong input? [duplicate]

This question already has an answer here:

The input is a word. If the word is hello it should print: Hello sir etc if the input is not hello it should print: why dont you say hello? The problem is that it always prints: Why dont you say hello? Why is this?

Scanner input =new Scanner(System.in);
String word=input.nextLine();
if(word=="hello"){
    System.out.println("hello sir have a good day");
}
else{
    System.out.println("Why dont you say hello?");
}

Aucun commentaire:

Enregistrer un commentaire