ABOUT SCANNERS

 

Rule #1 – Use one Scanner.

Students seem to have issues with CCC grader when using two Scanners.  It’s possible that this was simply caused by not properly closing them.  But it’s best to stick with just one at all times.


Rule #2 – Use scr.next() instead of scr.nextLine() if possbile


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.