mercredi 22 juillet 2015

My If-then-else statement isn't working? [duplicate]

This question already has an answer here:

I want to be able to make this work but for some reason it isn't initiating.

Scanner userInput = new Scanner(System.in);

System.out.println("Welcome to black jack. Are you ready to play?\nEnter 'Yes' or 'No'.");
System.out.println(""); //line spacing
String confirm = userInput.nextLine();
System.out.println(""); //line spacing

if (confirm == "Yes") {

    System.out.println("Testing");
    //going to put code to play game in here

} else if (confirm == "No") {
    System.out.println("Testing 2");
    System.exit(0);
} else {
    System.out.println("ERROR");
    System.out.println(""); //line spacing
}

Aucun commentaire:

Enregistrer un commentaire