我用Java制作了一个小程序:
String grade = JOptionPane.showInputDialog("What is your grade?");
switch (grade)
{
case "A":
JOptionPane.showMessageDialog(null, "You got an A - Well done!");
break;
case "B":
JOptionPane.showMessageDialog(null, "You got a B - Very good!");
break;
case "C":
JOptionPane.showMessageDialog(null, "You got a C - Good!");
break;
case "D":
JOptionPane.showMessageDialog(null, "You got a D - Study better next time!");
break;
default:
JOptionPane.showMessageDialog(null, "Invalid grade!");
}
}
}
现在,问题是——如果用户输入了一个无效的成绩,“无效的成绩!” 出现消息,按“确定”后它就关闭了。
成绩无效提示后如何让程序返回输入阶段?