I am writing a simple program that takes multiple inputs and displays the largest then second largest. My only problem is that I want the program to accept only single digi
//Set the counter
counter++;
while (true) {
//Input integer, set the largest number as the first output
number = Integer.parseInt(JOptionPane.showInputDialog("Enter integer"));
if (number < 10 && number > -10) break; //If it's one digit, it's OK
JOptionPane.showMessageDialog(null, "Enter only one digit",
"Too many digits", JOptionPane.ERROR_MESSAGE);
}
What this does is start an infinite loop. If the number is only one digit, it will end the loop and continue on. Otherwise, it will start from the beginning of the loop again and ask for a valid number.