我是一個開始的程序員,我試圖編寫一個簡單的程序,提出問題,然後以輸入「A」,「B」或「C」的形式提示您輸入該問題的答案對話框,但沒有出現對話框。其他一切似乎都很好。我如何製作它,讓我的測驗讓我回答?
這裏是我的代碼:
package homework;
import javax.swing.JOptionPane;
public class Quiz {
public static void main(String[] args)
{
int x = 0;
String[] quizQuestion = {"What is the color of the sky?", "What is the
color of the sea?", "What is the color of the earth?"};
int score = 0;
String correct = "You are correct";
String incorrect = "You are incorrect";
String playerAnswerString = " ";
playerAnswerString.toUpperCase();
char playerAnswer = playerAnswerString.charAt(0);
JOptionPane.showMessageDialog(null, "Test Your Knowledge!");
JOptionPane.showMessageDialog(null, "Select an answer to the questions.");
for(x = 0; x < 3; x++)
{
JOptionPane.showMessageDialog(null, quizQuestion[x]);
while(quizQuestion.equals(0))
{
playerAnswerString = JOptionPane.showInputDialog(null, "A = Blue, B = Green, C = Brown");
if(playerAnswer == 'A')
{
JOptionPane.showMessageDialog(null, correct);
score++;
}
else
{
JOptionPane.showMessageDialog(null, incorrect);
}
}
while(quizQuestion.equals(1))
{
playerAnswerString = JOptionPane.showInputDialog(null, "A = Blue, B = Green, C = Brown");
if(playerAnswer == 'B')
{
JOptionPane.showMessageDialog(null, correct);
score++;
}
else
{
JOptionPane.showMessageDialog(null, incorrect);
}
}
while(quizQuestion.equals(2))
{
playerAnswerString = JOptionPane.showInputDialog(null, "A = Blue, B = Green, C = Brown");
if(playerAnswer == 'C')
{
JOptionPane.showMessageDialog(null, correct);
score++;
}
else
{
JOptionPane.showMessageDialog(null, incorrect);
}
}
}
JOptionPane.showMessageDialog(null, "You scored " + score + "/3.");
}
}
在此先感謝。
爲清晰起見進行了編輯。
你的問題是什麼?是不是按要求工作或顯示錯誤? – SpringLearner
你用'while(quizQuestion.equals(0))'爲什麼? – Christian
@javaBeginner,程序不會彈出輸入對話框來回答問題。 –