JAVA 数组排序
import java.util.*;class student {
int num;
String name = "";
String sex = "";
String master = "";
int math;
int chinese;
int english;
void in() {
Scanner reader = new Scanner(System.in);
System.out.println("请输入学号:");
num = reader.nextInt();
System.out.println("请输入姓名:");
while ((name = reader.nextLine()).equals("")) {
}
System.out.println("请输入性别:");
sex = reader.nextLine();
System.out.println("是否是班干:");
master = reader.nextLine();
System.out.println("请输入数学成绩:");
math = reader.nextInt();
System.out.println("请输入语文成绩:");
chinese = reader.nextInt();
System.out.println("请输入外语成绩:");
english = reader.nextInt();
System.out.println("我的学号是" + num + ",姓名是:" + name + ",性别" + sex + ",我"
+ master + "班干。");
}
double total() {
return math + chinese + english;
}
double average() {
return total() / 3;
}
}
public class app6_13 {
public static void main(String[] args) {
int i, j;
double temp;
student[] stu = new student[2];
for (i = 0; i < 4; i++) {
stu[i] = new student();
stu[i].in();
System.out.println(stu[i].total());
System.out.println(stu[i].average());
}
for (j = 0; j < 4; j++)
for (i = 0; i < 4 - j; i++)
if (stu[i].total() > stu[i + 1].total()) {
temp = stu[i].total();
stu[i].total() = stu[i + 1].total();
stu[i + 1].total() = temp;
}
for (i = 0; i < 4; i++)
System.out.println("学号" + stu[i].num + "总分" + stu[i].total());
}
}
stu[i].total() = stu[i + 1].total();
stu[i + 1].total() = temp;
这2句出错 , 要怎么才可以解决啊 ?