1

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.

STF
  • 1,485
  • 3
  • 19
  • 36
Lummii
  • 23
  • 3

1 Answers1

1

Use z.equals("n") to compare strings in java

Ghilas BELHADJ
  • 13,412
  • 10
  • 59
  • 99