Java foreach变量导致“错误”&书信电报;标识符>;“预期”;编译错误

Java foreach变量导致“错误”&书信电报;标识符>;“预期”;编译错误,java,foreach,Java,Foreach,我正在为Java入门课程做家庭作业。当我试图编译我的代码时,我得到了一个编译错误。我相信这很简单,但我无法找出错误的原因 注意,我收到的错误在源代码下面 /* Logical Design start // Declarations final String QUESTIONS[] = new String{"Please input your answer using A, B, or C.\nWho is the coolest guy ever? \n\nA. Max\nB. J

我正在为Java入门课程做家庭作业。当我试图编译我的代码时,我得到了一个编译错误。我相信这很简单,但我无法找出错误的原因

注意,我收到的错误在源代码下面

/* Logical Design

start
  // Declarations
  final String QUESTIONS[] = new String{"Please input your answer using A, B, or C.\nWho is the coolest guy ever? \n\nA. Max\nB. James Bond\nC. Burt Reynolds", "Please input your answer using A, B, or C.\nWho do coolguys' drive?\n\nA. Datuns\nB. Panters\nC. Porsches", "Please input your answer using A, B, or C.\nWhat is the coolest city?\n\nA. Los Angles\nB. Denver\nC.Boulder"};
  final String CONGRATS = "You got it right!"
  final string FAIL = "Horribly. Horribly wrong. =["
  final String ANSWERS[] = new String{"A","A","A"};
  final String QUIT = "QUIT";
  String tempanswer[] = new String[3]
  int index;
  int index2;
  String keeplaying;


  Output "Would you like to play?"
  input keeplaying
  if(keepplaying == QUIT) {
  return;
  } else {
    for(index = 0; index<QUESTIONS.length; index++) {
    Output QUESTIONS[index]
    input tempanswer[index];
      for(index2 = 0; index2<ANSWERS.length; index2++) {
        if tempanswer == ANSWERS[index2] {
        output CONGRATS } else { output FAIL }
      }
    }
  }
stop
*/

import javax.swing.*;
import java.awt.event.*;

public class FunQuiz
{
  public static void main(String args[])
  {
  final String QUESTIONS[] = {"Please input your answer using A, B, or C.\nWho is the coolest guy ever? \n\nA. Max\nB. James Bond\nC. Burt Reynolds", "Please input your answer using A, B, or C.\nWhat do coolguys' drive?\n\nA. Datuns\nB. Panters\nC. Porsches", "Please input your answer using A, B, or C.\nWhat is the coolest city?\n\nA. Los Angles\nB. Denver\nC.Boulder"};
  final String ANSWERS[] = {"A","A","A"};
  final String QUIT = "QUIT";
  String tempanswer[] = new String[3];
  int index;
  int index2;
  String keeplaying;

  keepplaying = JOptionPane.showInputDialog("Would you like to play?");
  if(keepplaying == QUIT) {
  return;
  } else {
    for(index = 0; index<QUESTIONS.length; index++) {
    System.out.println(QUESTIONS[index]);
    JOptionPane.showInputDialog(tempanswer[index]);
      for(index2 = 0; index2<ANSWERS.length; index2++) {
        if(tempanswer == ANSWERS[index2]) {
        System.out.println("You got question " . index2 . " correct!");} else { System.out.println("You got question " . index2 . " incorrect.");}
      }
    }
  }

  System.exit(0);
  }
}
/*逻辑设计
开始
//声明
最后的字符串问题[]=新字符串{“请使用A、B或C输入您的答案。\n谁是有史以来最酷的人?\n\n.Max\nB.James Bond\nC.Burt Reynolds”,“请使用A、B或C输入您的答案。\n coolguys的驱动器是什么?\n\n\n.Datuns\nB.Panters\nC.Porsches”,“请用A、B或C输入答案。\n哪个城市最酷?\n\n洛杉矶\n丹佛\n博尔德”};
最后一个字符串祝贺=“你答对了!"
最后一个字符串非常失败。大错特错=["
最终字符串答案[]=新字符串{“A”、“A”、“A”};
最后一个字符串QUIT=“QUIT”;
字符串tempanswer[]=新字符串[3]
整数指数;
int index2;
弦乐演奏;
输出“您想玩吗?”
输入保持播放
如果(keepplaying==退出){
返回;
}否则{

对于(index=0;index使用
System.out.println(“您有问题”+index2+“正确!”);}
而不是

System.out.println("You got question " . index2 . " correct!");};

Java使用+进行连接。

使用
System.out.println(“您有问题”+index2+“正确!”);}
而不是

System.out.println("You got question " . index2 . " correct!");};

Java使用+进行连接。

在Java中,连接符号不是“.”,而是“+”

使用
System.out.println(“您有问题”+index2+“correct!”);}

在JAVA中,连接simbol不是“.”,而是“+”

使用
System.out.println(“你有问题”+index2+“正确!”);}

谢谢兄弟。太完美了。谢谢兄弟。太完美了。