0

When I run this if loop program, it always returns "You're not Harry", even if I enter "Harry". I'm running Eclipse Oxygen.

import java.util.Scanner;

class Hey {
    public static void main(String args[]) {
        Scanner Myscanner = new Scanner(System.in);
        java.lang.String x;
        System.out.println("Enter name:");
        x = Myscanner.nextLine();
        if (x == "Harry") {
            System.out.println("You're Harry");
        } else {
            System.out.println("You're not Harry.");
        }

    }
}
Ivar
  • 6,138
  • 12
  • 49
  • 61
harry
  • 157
  • 7

0 Answers0