在我最后一个介绍 Java 的项目中,我决定做一个 Mastermind Peg Game。
这是提交按钮代码:
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
Integer guess1, guess2, guess3, guess4;
Integer rightnumber = 0, rightposition = 0;
guess1 = Integer.parseInt (firstInput.getText());
guess2 = Integer.parseInt (secondInput.getText());
guess3 = Integer.parseInt (thirdInput.getText());
guess4 = Integer.parseInt (fourthInput.getText());
//Values are compared to the actual guess.
//(THIS IS WHERE I GET THE FOLLOWING ERROR:
//"cannot find symbol, symbol : variable answerdigit,
//location: class finalproject.Singleplayer"
if ( guess1 == answerdigit[0]);
{
rightposition = rightposition + 1;
}
}
这是开始按钮。在这里,产生了 4 位数的答案/代码。
private void startButtonActionPerformed(java.awt.event.ActionEvent evt)
{
// Declare variables for 4 digit answer, guess for each number
Integer one, two, three, four;
//Generate random number between 1 and 6 for each digit in the answer
int[] answerdigit = new int[4];
for(int i=0;i<4;i++)
{
answerdigit[i]=(int)(Math.random()*6+1);
}
}
我收到一个错误:
cannot find symbol, symbol : variable answerdigit, location: class finalproject.Singleplayer
我不明白错误是什么意思。