mardi 29 mars 2016

Java if statements only displaying the else statement [duplicate]

This question already has an answer here:

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