我想编写一个 java 程序,在其中询问用户他们想要回答多少数学问题,并使用任何选择循环根据他们的答案生成随机问题,并记录他们回答正确的数量。我得到它来生成随机数学问题,但它只在它似乎跳过循环时才这样做。任何人都可以帮忙吗?
import javax.swing.JOptionPane;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author user
*/
public class MathQuiz {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Random obj = new Random();
int num1 = obj.nextInt(10);
int num2 = obj.nextInt(10);
int rand = num1 + num2;
String response = JOptionPane.showInputDialog(null,"How many problems would you like to solve?");
int ans = Integer.parseInt(response); // answer from question
String result= null;
int times = input.nextInt();
int counter = 0; //counts total math problems
while (counter != ans){
counter++;
JOptionPane.showInputDialog(num1 + "+" +num2);
if (ans == rand){
result= "Correct";
}else {
result= "Incorrect";
}
} JOptionPane.showMessageDialog(null, );
}
}
catspeake
红糖糍粑
相关分类