public class HelloWorld {
public static void main(String[] args) {
int[] sorname = {89,-23,64,91,119,52,73,99,100};
HelloWorld dxname = new HelloWorld();
int[] backsorname = dxname.ffname(sorname);
System.out.println("考试成绩的前三名为:");
for(int i=(backsorname.length-1);(i>backsorname.length-4);i--) {
System.out.println(backsorname[i]);
}
}
public int[] ffname(int[] sorname) {
int a=0;
for(int i=0;i<sorname.length;i++) {
if(sorname[i] >=0 && sorname[i] <= 100) {
a=a+1;
}
}
int[] backsorname = new int [a];
int c = 0;
for(int b=0;b<sorname.length;b++) {
if(sorname[b] >=0 && sorname[b] <= 100) {
backsorname[c]=sorname[b];
c=c+1;
}
}
Arrays.sort(backsorname);
return backsorname;
}
}
for(int i=(backsorname.length-1);(i>backsorname.length-4);i--);这句应该不用上括号吧;
a=a+1;事先需要int a=0定义;然后把a=a+1改为a++;
int[] backsorname数组这个应该先给分配空间呀;然后再给赋值