我一直得到这个错误的帮助请...令牌“;”的语法错误,预期

时间:2013-03-08 16:20:04

标签: java

我在这个问题上收到一个错误,上面写着令牌“;”的语法错误。我做错了什么或我错过了什么,错误来自字符串输入字符串。我试图创建我可以放入学生成绩的地方,然后将成绩平均在一起,所以我不确定我是否做得对。请帮忙!!!有关如何做到这一点的任何想法?非常感谢帮助。

import java.util.Scanner;         //To hold the users score

import javax.swing.JOptionPane;  //For better style

 import java.text.DecimalFormat; //needed to format the Output


public class TestScore
{//begin class

    public static void main(String[] args)

    {//Begin main method



        //create the variables

     String inputString ;       // For reader's input

               DoubleScore1,      //Define DoubleScore 1

                DoubleScore2,     //Define DoubleScore 2

                DoubleScore3,    //Define DoubleScore 3

                AverageScore; //Define AverageScore



Scanner keyboard = new Scanner(System.in); //To hold the users grade


DecimalFormat formatter = new DecimalFormat("#,##0.00"); //format the scores



        //create keyboard for input

        Scanner Keyboard = new Scanner(System.in);



        //Ask the user to input DoubleScore1

        inputString=

          JOptionPane.showInputDialog("Please enter test score 1");



            // Convert the input to a double.

             DoubleScore1 = Double.parseDouble(inputString);



        //Ask the user to input DoubleScore

        inputString=

          JOptionPane.showInputDialog("Please enter test score 2");



            // Convert the input to a double

        DoubleScore2 = Double.parseDouble(inputString);



        //Ask the user to input DoubleScore

        inputString=

          JOptionPane.showInputDialog("Please enter test score 3");



            // Convert the input to a double

            DoubleScore3 = Double.parseDouble(inputString);







        //Calculate the average score for the tests

        AverageScore = ((DoubleScore1 + DoubleScore2 + DoubleScore3)/3);



        //Display Average test Score

        JOptionPane.showMessageDialog(null, "\t\nYour Double Score 1  is : "     +formatter.format(DoubleScore1)

                                      + "\t\nYour Double Score 2  is : " +formatter.format(DoubleScore2)

                                      + "\t\nYour Double Score 3  is : " +formatter.format(DoubleScore3)

                                      + "\t\nYour Average Score is: " +     formatter.format(AverageScore));

            //End the program.

          System.exit(0);



    }//End main method



}//end class`enter code here`

2 个答案:

答案 0 :(得分:1)

这个

String inputString ;       // For reader's input

               DoubleScore1,      //Define DoubleScore 1

                DoubleScore2,     //Define DoubleScore 2

                DoubleScore3,    //Define DoubleScore 3

                AverageScore; //Define AverageScore

应该是

String inputString ,       // For reader's input

               DoubleScore1,      //Define DoubleScore 1

                DoubleScore2,     //Define DoubleScore 2

                DoubleScore3,    //Define DoubleScore 3

                AverageScore; //Define AverageScore

;将结束该行,因此下一行必须再次声明该字段或使用,来表示它也是相同的类型。

               String inputString;       // For reader's input

               Double DoubleScore1,      //Define DoubleScore 1

                      DoubleScore2,     //Define DoubleScore 2

                     DoubleScore3,    //Define DoubleScore 3

                   AverageScore; //Define AverageScore

答案 1 :(得分:1)

您需要声明变量DoubleScore的类型:

double DoubleScore1;