forked from coding-technology/JavaCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestStudent.java
More file actions
58 lines (46 loc) · 1.79 KB
/
TestStudent.java
File metadata and controls
58 lines (46 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class TestStudent {
//{stu1,stu2,stu3}
public static void compareStudent(Student[] students) {
//冒泡排序 1 5 9 10 25
for (int i = 0; i < students.length - 1; i++) {
for (int j = 0; j < students.length - 1 - i; j++) {
if (students[j].getSum() < students[j + 1].getSum()) {
//交换 int
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
}
public static void main(String[] args) {
Student stu1 = new Student();
stu1.name = "zs";
stu1.javaScore = 99;
stu1.sqlScore = 98;
Student stu2 = new Student();
stu2.name = "ls";
stu2.javaScore = 98;
stu2.sqlScore = 98;
Student stu3 = new Student();
stu3.name = "ww";
stu3.javaScore = 100;
stu3.sqlScore = 98;
double stu1Avg = stu1.getAvg();
double stu2Avg = stu2.getAvg();
double stu3Avg = stu3.getAvg();
System.out.println(stu1.name + "\t" + stu1.getSum() + "\t" + stu1.getAvg());
System.out.println(stu2.name + "\t" + stu2.getSum() + "\t" + stu2.getAvg());
System.out.println(stu3.name + "\t" + stu3.getSum() + "\t" + stu3.getAvg());
Student[] students = new Student[]{stu1, stu2, stu3};
for (Student student : students) {
System.out.println(student.name + "\t" + student.getAvg() + "\t" + student.getSum());
}
compareStudent(students);
//
System.out.println("---");
for (int i = 0; i < students.length; i++) {
System.out.println(students[i].name + "\t" + students[i].getAvg() + "\t" + students[i].getSum());
}
}
}