我的代码是这样的......所有问题都不一样......但是当我尝试它时,它会一次又一次地重复同样的问题。或者,它不会显示所有问题......
import java.util.Random;
import javax.swing.JOptionPane;
public class Questions extends JFrame {
public static void main(String[] args) {
int[] questionsdone = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
Random rnd = new Random();
for (int i = 0; i < 40; i++) {
int ramNum = rnd.nextInt(30);
//randomly choose a number between 0 to 30
int checkingSize = 0;
for (int z = 0; z < questionsdone.length; z++) {
if (questionsdone[z] != ramNum) {
checkingSize++;
if (checkingSize == 20) {
questionsdone[i] = ramNum;
String answer = JOptionPane.showInputDialog(null, questions[z], "Grade 11 Computer Science Review Exercise", JOptionPane.INFORMATION_MESSAGE);
//show the questions
if (answer.equals(answers[z])) {
JOptionPane.showMessageDialog(null, "Correct! The answer is " + answers[z], "Grade 11 Computer Science Review Exercise", JOptionPane.INFORMATION_MESSAGE);
mark = mark + 1;
} else {
JOptionPane.showMessageDialog(null, "Wrong! The answer shuold be " + answers[z], "Grade 11 Computer Science Review Exercise", JOptionPane.INFORMATION_MESSAGE);
}
}
//check the answers
if (questionsdone.length == 20) {
break;
}
} //end if
} //end for
} //end for
}
}