저는 처음 프로그래머입니다. 질문을하는 간단한 프로그램을 작성하려고합니다. 입력에 "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에서 프로그램은 질문에 대답하기 위해 입력 대화 상자를 팝업하지 않습니다. –