-1
누군가 왜 while 루프가 whatNight를 두 번 묻는 지 설명 할 수 있습니까? 어떻게 유효하지 않은 사용자 입력을 다시 메시지 표시하는 경우 'R'또는 'C'어떻게 잘못된 사용자 입력을 reprompt하고 값을 복원합니까?
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;
}