Do-while循环里面的for循环
我有一个问题,我不能用java循环来解决类练习。我需要编写一个程序,提出10个随机乘法表的问题。在10道问题结束时,它必须向我展示第一次正确的问题。如果问题不是第一次,它必须显示失败号码的表格,然后重新提出问题。
我现在面临的问题是,在10个问题的范围内,我有一个如果 - 正确的问题和其他内部的问题 - 而重新提出问题。问题是,当我没有问题时,程序重新编写了它,但是如果我输入正确的答案,那么do-while循环会关闭并停止提问。
练习中禁止使用数组。
下面是代码:
for (int i=1; i<=10; i++) {
Tablas operacion=new Tablas();
int pregunta = Integer.parseInt(JOptionPane.showInputDialog(null, operacion.getNumeroPregunta()+"\n"+operacion.multiplicacion()));
if (pregunta == operacion.resultado()) {
Tablas.comprobadorPreguntas(true);
}
else {
do {
String salida="";
for (i=1; i<=10; i++) {
salida+=operacion.getMultiplicando() + "x"+i+"=" + (operacion.getMultiplicando() * i) + "\n";
}
JOptionPane.showMessageDialog(null, salida);
pregunta = Integer.parseInt(JOptionPane.showInputDialog(null, operacion.getNumeroPregunta()+"\n"+operacion.multiplicacion()));
} while(pregunta != operacion.resultado());
Tablas.comprobadorPreguntas(false);
}
}
JOptionPane.showMessageDialog(null, "Preguntas acertadas a la primera: "+Tablas.getContador());
这里同时在引擎收录类:
计划>https://pastebin.com/imAQBuRX
方法>https://pastebin.com/GJdyrnRv