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那麼它會給出錯誤對話框。我遇到的問題是,錯誤對話框「一個不能等於x」會一直出現,並在打好時不會關閉。我認爲它與for循環有關,但我無法弄清楚。循環錯誤消息
我沒有看到你在做什麼。我相信一個更好的方法是使用String類中的split方法來分隔'='符號部分和'='符號部分之後的部分。 – pattmorter 2013-02-27 04:52:37
嗯我不知道這件事,我認爲它更好地工作,謝謝你的提示。 – Mert 2013-02-27 05:04:54