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,447
  • 3
  • 18
  • 33
Lummii
  • 23
  • 3

1 Answers1

1

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

Ghilas BELHADJ
  • 12,402
  • 10
  • 54
  • 88