This question already has an answer here:
- Loop user input until conditions met 3 answers
I cant seem to get the program to ask again for a valid input after an invalid input and then check that new input again. I know I need a combination of if and while loops but I cant seem to get the logic correct.
Heres where the problem occours:
// Validate input is in range
if (amtBars < 40 && amtBars > 10)
// Prompt for bar type
barType = JOptionPane.showInputDialog(null, "Please input a symbol, letter, or phrase to compose each bar:", HEADING, JOptionPane.INFORMATION_MESSAGE);
else
{
JOptionPane.showMessageDialog (null, "Value must be between 10 and 40.", HEADING, JOptionPane.INFORMATION_MESSAGE);
inBars = JOptionPane.showInputDialog(null, "Please input a number between 10 and 40:", HEADING, JOptionPane.INFORMATION_MESSAGE);
amtBars = Integer.parseInt(inBars);
}
The information will be "validated" once but then once the else is reached it will not validate again and take whatever input the user keys.
How might I go about setting up the proper while loop?
Aucun commentaire:
Enregistrer un commentaire