程序总结未编译的成绩

时间:2014-12-07 01:39:38

标签: java debugging compilation

我遇到编译错误,这个程序语言是Java。 它是一个简单的程序,可以为用户提供等级和打印统计数据......任何帮助都会很棒......

现在进一步发展 这是错误输出:

C: - 11 \ SummariseGrades.java:60:错误:不兼容的类型:int无法转换为int []             for(int []年级:studentGrades)                                 ^ C: - 11 \ SummariseGrades.java:63:错误:二元运算符'<'的错误操作数类型                 if(等级< lowGrade)                           ^   第一种类型:int []   第二种类型:int C: - 11 \ SummariseGrades.java:64:错误:不兼容的类型:int []无法转换为int                 lowGrade = grade;                            ^ C: - 11 \ SummariseGrades.java:82:error:找不到符号         for(int []年级:studentGrades)                            ^   符号:变量studentGrades   地点:班级SummariseGrades C: - 11 \ SummariseGrades.java:85:错误:不兼容的类型:int无法转换为int []             for(int [] studentGrades:grade)                                        ^ C: - 11 \ SummariseGrades.java:88:错误:二元运算符'>'的错误操作数类型                 if(等级> highGrade)                           ^   第一种类型:int []   第二种类型:int C: - 11 \ SummariseGrades.java:89:error:不兼容的类型:int []无法转换为int                 highGrade = grade;                             ^ C: - 11 \ SummariseGrades.java:123:错误:变量等级已在方法outputBarChart(int [] [])中定义             for(int [] grade:studentGrades)                         ^ C: - 11 \ SummariseGrades.java:123:错误:不兼容的类型:int无法转换为int []             for(int [] grade:studentGrades)                                  ^ C: - 11 \ SummariseGrades.java:124:错误:找不到符号             ++频率[等级/ 10];                           ^   符号:可变等级   地点:班级SummariseGrades C: - 11 \ SummariseGrades.java:166:错误:找不到符号         System.out.printf(“Student%2d”,student + 1);                                           ^   符号:变量学生   地点:班级SummariseGrades C: - 11 \ SummariseGrades.java:168:错误:找不到符号         for(int test:grade [student])//输出学生成绩                                  ^   符号:变量学生   地点:班级SummariseGrades C: - 11 \ SummariseGrades.java:173:错误:找不到符号         double average = getAverage(成绩[学生]);                                               ^   符号:变量学生   地点:班级SummariseGrades 13个错误

工具已完成,退出代码为1

******这是代码

  public class SummariseGrades
 {
    public static void main (String[]args)
   {
    //2d array of student grades
    int [][] gradesArray =
    { { 87,96,70 },
      { 68,87,90 },
      { 94,100,90 },
      { 100,81,82},
      { 83,65,85},
      { 78,87,85},
      { 85,75,83},
      { 91,94,100},
      { 76,72,84},
      { 87,93,73}  };

    //output grades array
    outputGrades ( gradesArray );

    //call methods getMinimum and getMaximum
    System.out.printf ("\n %s %d \n %s %d \n \n",
    "Lowest grade is", getMinimum ( gradesArray ),
    "Highest grade is", getMaximum (gradesArray ) ) ;

    //output grade distribution chart of all grades on all tests
    outputBarChart (gradesArray);

} //end main





//find minimum grade
  public static int getMinimum (int grades [][])
{
    //assume first element of grades array is the minumum
    int lowGrade = grades [0][0];

    //loop through rows of grades array
    for (int [] studentGrades : grades )
    {
        //loop throught the columns of current row
        for (int [] grade : studentGrades )
        {
            //if grade less than lowGrade, assign it to lowGrade
            if (grade < lowGrade)
            lowGrade = grade ;
        } //end inner
    }//end outer

    return lowGrade;  // returns lowest grade
  } //end method getMinimum





    //find maximum grade
    public static int getMaximum (int grades [][])
    {
    //assume first element is the largest in array
    int highGrade = grades [0][0];

    //loop through rows of the grades array
    for (int[] grade : studentGrades)
    {
        //loop through columns of the current row
        for (int[] studentGrades : grade)
        {
            //if grade greater than highGrade then assign it to highGrade
            if (grade > highGrade)
            highGrade = grade;
        } //end inner
    } //end outer

    return highGrade;  // return highest grade

} //end method getMaximum



  //determine average grade for particular set of grades
  public static double getAverage (int[] setOfGrades )
  {
    int total = 0;  // initialise total

    //sum grades for one student
    for (int grade : setOfGrades)
    total += grade;

    //return average of grades
    return (double) total / setOfGrades.length;
    } //end method for getAverage

    //output bar chart displaying overall grade distribution
    public static void outputBarChart (int grades[][])
   {
    System.out.println ("Overall grade distribution:");

    //stores the frequency of grades in each range of 10 grades
    int[] frequency = new int [11];

    // for each grade in the grade book, increment the appropriate frequency
    for (int [] studentGrades : grades)
    {
        for (int [] grades : studentGrades)
        ++frequency [ grade / 10 ];
    } //end outer

    //for each grade freq, print bar in chart
    for (int count = 0 ; count < frequency.length ; count++)
    {
        //output bar label
        if (count ==10)
        System.out.printf ( "%5d: ", 100);

        else
            System.out.printf ("&02d-%02d: ",
            count * 10, count * 10 + 9 );

        //print bar of asterisks
        for (int stars = 0 ; stars < frequency [ count ] ; stars++)
            System.out.print ("*");

        System.out.println();  //start a new line of output

    } //end outer for loop

  } //end method for outputBarChart

  //output contents of the grades array

   public static void outputGrades ( int grades [][])
   {
    System.out.println ("The grades are:\n");
    System.out.print ("             "); //align column heads

    // create a column heading for each of the tests

    for (int test = 0 ; test < grades [0].length; test ++)
        System.out.printf ("Test %d ", test + 1);

        System.out.println ("Average");  //student average column heading

    //create rows and columns of text representing array grades

    for (int student = 0 ; student < grades.length ; student ++);
    {
    System.out.printf ("Student %2d", student + 1);

    for ( int test: grades [ student ] ) // output student grades
        System.out.printf ("%8d", test );

    // call method getAverage to calculate the student's average grade
    // pass row of grades as the argument to getAverage
    double average = getAverage (grades [ student ] ) ;
    System.out.printf ("%9.2f \r", average );

  } // end outer for
 } // end method outputGrades
} // end class Summerise Grades

1 个答案:

答案 0 :(得分:3)

复制将代码粘贴到IDE中并出现Syntax error on token ")", delete this token错误(将来,请发布您确切的编译错误)

这是因为您在)电话的第一行末尾有一个额外的System.out.printf

 System.out.printf ("\n %s %d \n %s %d \n \n",
    "Lowest grade is", getMinimum ( gradesArray ),
    "Highest grade is", getMaximum (gradesArray ) ) ;