簡單的百分比計算。它不會返回0.0以外的值,我認爲有一次或兩次返回100.0%。除此之外,它不會做一件事。我嘗試過用幾種不同的方式來玩代碼,它只是不會工作。計算出來0.0?
for (int loop = 1; loop < loopCount; loop++)
{
aa = r.nextInt(10+1);
abc = (int) aa;
String[] userAnswer = new String[x];
int totalQues = (correctAnswer + wrongAnswer), actualQues = (totalQues - 1);
if(abc < x)
{
userAnswer[abc] = JOptionPane.showInputDialog(null,"Question "+quesNum+"\n\n"+questions[abc]+"\n\nA: "+a[abc]+"\nB: "+b[abc]+"\nC: "+c[abc]+"\nD: "+d[abc]+"\nCorrect Answers: "+correctAnswer+"\nWrong Answers: "+wrongAnswer+"\nTotal Questions: "+totalQues);
if(userAnswer[abc].equals(answers[abc]))
{
correctAnswer++;
}
else
{
wrongAnswer++;
}//else
if(actualQues == x);
{
score = (correctAnswer/actualQues) * 100;
JOptionPane.showMessageDialog(null,"The test is finished.");
JOptionPane.showMessageDialog(null,"You scored "+score+"%");
}//if
}//if
}//for
aa = r.nextInt(10 + 1) 您有這樣做的原因嗎?這與aa = r.nextInt(11)是一樣的。您可能想要aa = r.nextInt(10)+ 1. – 2010-06-03 16:15:49