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