Scanner.nextLine() not returning null?
<p>I'm a student and I decided to try out some of the problem sets at UVa Online Judge to help improve my skill.  I ran into a brick wall on the first problem.  After fighting compiler errors (I <em>finally</em> found some vague guidelines for submitting Java code in their forums), I've now graduated to "Wrong Answer" status.</p>

<p>To get to the point -- if I don't surround this while loop with a try/catch, it generates a <code>NumberFormatException</code> at runtime on input string <code>""</code> on the call to <code>Integer.parseInt()</code>.  That makes sense, except if input is <code>""</code> then it is <code>null</code> and should not enter the loop.</p>

<p>I've tried getting rid of <code>split(" ")</code> and use a <code>StringTokenizer</code>, but that generates an wrong index exception.</p>

<p>The program works fine until I end input by hitting Enter.  That's when the error generates.  If I surround the loop with a try/catch, there's no errors, but the console seems to throw in an additional line break, and I believe that's the source of my "Wrong Answer" status.</p>

<p>What am I doing wrong?</p>

<pre><code>public static void main(String[] args){
     Scanner kb = new Scanner(System.in);
     String input;
     String[] temp;
     int i, j;

     while( (input = kb.nextLine()) != null ){
        temp = input.split(" ");
        i = Integer.parseInt(temp[0]);
        j = Integer.parseInt(temp[1]);
        solve(i, j);
     }
}
</code></pre>
