-1
任何人都可以解釋爲什麼while循環問whatNight兩次?以及如何重新提示無效的用戶輸入,如果用戶輸入的東西比「R」或「C」我如何報告無效的用戶輸入並恢復該值?
for(int x = 1; x <= inputInt; x++) {
char whatNight = JOptionPane.showInputDialog("Enter c or r for what type of night").charAt(0);
boolean pleasework = whatNight == 'c' || whatNight == 'C';
boolean imbeggingu = whatNight == 'r' || whatNight == 'R';
boolean doesNotWork = whatNight != 'c' && whatNight != 'C' && whatNight != 'r' && whatNight != 'R';
//why does the while loop ask twice even if u enter c or r?
while(pleasework || imbeggingu || doesNotWork) {
if(doesNotWork)
JOptionPane.showMessageDialog(null, "INvalid letter");
whatNight = JOptionPane.showInputDialog("Enter c or r for what type of night").charAt(0);
//reprompt not storing in whatNight variable :/
if(pleasework)
JOptionPane.showMessageDialog(null, "You entered c for carnight");
else if(imbeggingu)
JOptionPane.showMessageDialog(null, "You entered r for regular night");
break;
}