Stopping reading inputs when an empty line is entered while entering the input one after another is one of the frequently encountered errors in Java. The solution is to check user inputs.
Java Stop Reading After Empty Line
If we are using for loop to fill the array with user input, it is necessary to rewind the for loop by checking the empty lines entered by the user and only get the validated inputs
String array = new String;
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter 10 inputs");
for (int i=0; i<10; i++)
String input = scanner.nextLine();
array[i] = input;
Please enter 10 inputs
[hi, hello, test, blank, empty, line, 1, 2, 3, 4]
© Copyright Vitademy 2023. All rights reserved.