This question already has an answer here:
- How do I compare strings in Java? 23 answers
Hey im coding a simple program for java and im having problems with my if and else statements.
Scanner coffee = new Scanner(System.in);
String z = coffee.nextLine();
if (z == "y")
System.out.println("Great! Let's get started.");
else if (z == "n")
System.out.println("Come back next time, " + x + "." );
else
System.out.println("Error please try again");
Where it only comes up with the else statement.
Aucun commentaire:
Enregistrer un commentaire