I have a problem with last line of input. I cannot force Scanner to read a number from last line since it is unfinished. When I copy input with one more line after the previous last line, there is no problem, but i cannot have the extra line there.
Example of input:
2
1 1
9 9
4
4 5
6 5
2 5
3 4
-1
I've tried sc.nextInt()
, sc.next()
, sc.nextLine()
and nothing can reach the -1
. Even sc.hasNext
, sc.hasNextInt
etc. are waiting.
while(true)
{
line = sc.nextLine();
try {
a = Integer.parseInt(line);
}
catch (NumberFormatException e) {
}
if(a == -1)
{
break;
}
rr = new int[a][2];
for(int i = 0; i < a; i++)
{
line = sc.nextLine();
numbers = line.split(" ");
try {
rr[i][0] = Integer.parseInt(numbers[0]);
rr[i][1] = Integer.parseInt(numbers[1]);
}
catch (NumberFormatException e) {
}
}
b = sc.nextInt();
sc.nextLine();
tt = new int[b][2];
for(int i = 0; i < b; i++)
{
line = sc.nextLine();
numbers = line.split(" ");
try {
tt[i][0] = Integer.parseInt(numbers[0]);
tt[i][1] = Integer.parseInt(numbers[1]);
}
catch (NumberFormatException e) {
}
}
sc.nextLine();
}