import java.io.*;
import java.util.*;
public class Grade
{//class
public static void main (String [] args)
{//main
Scanner keyBoard = new Scanner(System.in);
int [] gradeFreq = new int [101];`enter code here`
int input = 0;
System.out.print ("Enter next grade: ");
input = keyBoard.nextInt();
while(input >= 0){
gradeFreq[input]++;
System.out.print("Please enter next grade");
input = keyBoard.nextInt();
}
System.out.print ("To show results in ascending order press 1... or 2 for descending");
input = keyBoard.nextInt();
switch(input){
case 1:
printUp(gradeFreq);
break;
case 2:
printDown(gradeFreq);
break;
}
public static void printUp(int[] array){
System.out.print("Ascending");
for(int i = 0; i < array.length; i++){
if(array[i] > 0)
System.out.printf("%5d\t%5d\n",i,array[i]);
}
}
public static void printDown(int[] array){
System.out.print("Descending");
for(int i = 0; i < array.length; i--){
if(array[i] > 0)
System.out.printf("%5d\t%5d\n",i,array[i]);
}
}
}//end of main
}//end of class
我有这个错误。
Grade.java:37: error: illegal start of expression
public static void printUp(int[] array){
^
Grade.java:37: error: illegal start of expression
public static void printUp(int[] array){
^
Grade.java:37: error: ';' expected
public static void printUp(int[] array){
^
Grade.java:37: error: '.class' expected
public static void printUp(int[] array){
^
Grade.java:37: error: ';' expected
public static void printUp(int[] array){
^
Grade.java:44: error: illegal start of expression
public static void printDown(int[] array){
^
Grade.java:44: error: illegal start of expression
public static void printDown(int[] array){
^
Grade.java:44: error: ';' expected
public static void printDown(int[] array){
^
Grade.java:44: error: '.class' expected
public static void printDown(int[] array){
^
Grade.java:44: error: ';' expected
public static void printDown(int[] array){
^
10 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
我只是尝试使用一种方法以升序或降序显示我的数组(取决于用户选择的内容)。当我编译代码时,每个方法的第一行都会出现大约 10 个错误。我在谷歌上查过,我找不到任何有用的东西。请帮帮我。----jGRASP exec: javac -g Grade.java