【发布时间】:2014-12-07 01:39:38
【问题描述】:
我收到编译错误,这个程序语言是 Java。 它是一个简单的程序,可以为用户获取成绩并打印统计数据......任何帮助都会很棒......
现在更进一步 以下是错误输出:
C:--11\SummariseGrades.java:60: 错误:不兼容的类型:int 无法转换为 int[] for (int [] 等级 : studentGrades ) ^ C:--11\SummariseGrades.java:63: 错误:二元运算符 '' 的操作数类型错误 如果(等级>高等级) ^ 第一种:int[] 第二种类型:int C:--11\SummariseGrades.java:89: 错误:不兼容的类型:int[] 无法转换为 int 高等级 = 等级; ^ C:--11\SummariseGrades.java:123: 错误: 变量等级已经在方法 outputBarChart(int[][]) 中定义 for (int [] 成绩 : studentGrades) ^ C:--11\SummariseGrades.java:123:错误:不兼容的类型:int 无法转换为 int[] for (int [] 成绩 : studentGrades) ^ C:--11\SummariseGrades.java:124: 错误:找不到符号 ++频率[等级/ 10]; ^ 符号:可变等级 地点:班级 SummariseGrades C:--11\SummariseGrades.java:166: 错误:找不到符号 System.out.printf ("学生 %2d", 学生 + 1); ^ 符号:可变学生 地点:班级 SummariseGrades C:--11\SummariseGrades.java:168: 错误:找不到符号 for ( int test: grades [ student ] ) // 输出学生成绩 ^ 符号:可变学生 地点:班级 SummariseGrades C:--11\SummariseGrades.java:173: 错误: 找不到符号 双重平均= 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
【问题讨论】:
-
识别所使用的编程语言有些重要,因为存在不止一种。
-
请更新您也收到的错误。
-
可能是错误的 # 或
()的位置,但我只是猜测,因为您没有告诉我们错误是什么。而且....这一次我的猜测是正确的。
标签: java debugging compilation