$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #228

Which fix removes the bug?

String answer = scanner.nextLine();
if (answer == "yes") {
    proceed();
}
  1. Use answer === "yes"
  2. Cast it: (String) answer
  3. Call answer.trim() first
  4. Use answer.equals("yes")
== compares object references; text read at runtime is a different object from the literal.
Play Problem Solving ▸