Scanner
does have a next
method, which reads a token regardless of type and returns it as a String, as well as a nextLine
method, which does what you expect. In general, I would suggest using next
or nextLine
over nextInt
and other type-specific methods, just because you may run into some unexpected behaviour if the input isn't exactly right.
Also, you shouldn't compare two strings with the ==
operator. In Java, ==
is a reference (or shallow) comparison, which essentially checks if two objects are stored in the same place on your computer; this works for primitive types (ints, doubles, etc.), because of how they're represented in the language. It will NOT work for Strings, because Strings are complex objects in Java. Instead you should use the equals
method, which will do a deep comparison - checking if all of the data is identical.