I'm trying to use a do-while loop to get information for an ArrayList
, but I get this output:
Please input your number (type a letter to finish): 2
3
Please input your number (type a letter to finish): 4
Please input your number (type a letter to finish): q
But the operation succeeds and ArrayList
contains all three numbers (2, 3, 4) as expected even without the prompt having been printed for one of them
do {
num = getNumber("Please input your number (type a letter to finish): ");
data.add(num);
} while (console.hasNextInt());
and the method getNumber
:
public static int getNumber(String prompt) {
System.out.print(prompt);
return console.nextInt();
}
How to I get it to print the prompt for all numbers?