如果我按下#34; no"如何停止此无限循环?在确认对话框上?
int loop=0;
do
{
System.out.println("Select your food. 1");
int f=scan.nextInt();
if(f==1)
{
System.out.println("\nHow many tenderloin do you like? ");
ps=scan.nextInt();
pst=ps*55;
}
System.out.println("Select your drinks. 1");
int d=scan.nextInt();
if(d==1)
{
System.out.println("\nHow many filtered water do you want? ");
fw=scan.nextInt();
fwt=fw*16;
}
int buttonClicked=JOptionPane.showConfirmDialog(null, "Do You Want To Order Again?","Confirm",JOptionPane.YES_NO_OPTION);
}
while(JOptionPane.YES_NO_OPTION!=done);
loop++;
System.out.println("TOTAL: ");
}
}
我无法获得逻辑。
答案 0 :(得分:1)
将buttonClicked
的定义移到循环外部。并根据值JOptionPane.YES_OPTION
进行测试。像,
int buttonClicked;
do
{
// ...
buttonClicked = JOptionPane.showConfirmDialog(null,
"Do You Want To Order Again?","Confirm",JOptionPane.YES_NO_OPTION);
} while(buttonClicked == JOptionPane.YES_OPTION);
答案 1 :(得分:0)
将此行while(JOptionPane.YES_NO_OPTION!=done);
更改为while(JOptionPane.NO_OPTION!=buttonClicked);