I have this Java input-related problem.
I’m solving some cases in UVAToolkit, but there are some problems that the line input requires from the System.in. Basing from these codes below, how could I terminate the problem once I’ve pressed key? The sample input/output are displayed below.
Scanner scanner = new Scanner(System.in);
String line;
while((line = scanner.nextLine()) != null) {
System.out.println(line);
}
System.out.println("done");
Sample Input:
1 10
10 100
100 1000
Sample Output:
1 10
10 100
100 1000
done
Thanks in advance.
Don’t check for null input but for an empty string. This way, you should be able to terminate just by pressing the return key.