Rule #1 – Use one Scanner.
The scanner method nextLine() reads in an entire line until an <ENTER> is found. It works well if it is the only Scanner method you are using. However, on the CCC, you sometimes have to read an int followed by a String. Using nextInt() followed by nextLine() would give you a problem. Thankfully, you can usually simply use nextInt() followed by next(). Another solution is to read all input as Strings and convert it to integers when needed. |