for(int i = 0 ; i < 10 ; i++)
{
out.println(9);
}
out.close();
while (s.hasNextLine()) {
int i = s.nextInt();
if ( i == 9);
{
System.out.print("*");
}
}
s.close();
It still prints out 10 "*", but i get this error afterward:
**********java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at insertionSort.main(insertionSort.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
But if I use hasNext instead of hasNextLine, it works fine.
So I am wondering why hasNext works, but hasNextLine doesn't.