String inputRules = JOptionPane.showInputDialog
(
"Enter your rules. \n" +
"In the form: a=x"
);
boolean gotGoodRuleInput = false;
while (!gotGoodRuleInput)
{
gotGoodRuleInput = true;
char a = inputRules.charAt(0);
for (int i= 2; i<inputRules.length(); i++)
{
char x = inputRules.charAt(i);
if (a == x)
{
JOptionPane.showMessageDialog
(
null,
"a can not equal x",
"Error",
JOptionPane.ERROR_MESSAGE
);
gotGoodRuleInput = false;
}
}
}
您好我正在尝试检查用户输入,如果 x 处的输入等于 a 那么它将给出错误对话框。我遇到的问题是错误对话框“a 不能等于 x”不断出现,并且在点击确定时不会关闭。我认为它与 for 循环有关,但我无法弄清楚。