0
  Scanner s = new Scanner(System.in);
  String x;

  do {
     x = s.next();
     System.out.println(x);
     if (x == "1") {
        System.out.println("working");
     }
  } while (x != "2");

This code prints the correct value of String x, but will never print "working" and does not end the do/while loop when x == 2. What is wrong with this code?

Dncn
  • 1

0 Answers0