数组与类
public class Test1 {
public static void main(String[] args) {
int[][] a = new int[20][3];
for(int i = 0; i < a.length; i++){
Student aa = new Student();
a[i][0] = i + 1;
a[i][1] = aa.state;
a[i][2] = aa.score;
}
for(int i = 1; i < a.length; i++){
for(int j = 0; j < a.length - i; j++){
if(a[j][2] < a[j+1][2]){
int[] temp;
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for(int i = 0; i < a.length; i++){
System.out.println(a[i][0] + "号" + a[i][1] + "年级,分数是:" + a[i][2]);
}
}
}
class Student{
int number;
int state;
int score;
public Student(){
state = (int)(Math.random() * 6) + 1;
score = (int)Math.round(Math.random() * 100);
}
}