I am trying to write this method, which keeps reading from the user, until the word \"exit\" is inputted. I tried with a break and for loop; it didn\'t work. I was trying wi
name == exit
is wrong.
You want
name.equals(exit)
or
name.equals("exit")
depending on whether exit is a variable or a string literal, respectively. In Java, ==
means reference equality (e.g Are these two references pointing to the same address in memory), whereas .equals
means object equivalence, which is typically overriden
in the class by the developer.