写了一个,我也是刚学,可能效率不是很高,但是,结果正确!
import java.lang.*;
class Student
{
String xm;
int xh;
float[] score;
float zongfen;
Student(String name,int num,float zhz,float yw,float sx,float com,float ty)
{
int i;
score=new float[5];
this.score[0]=zhz;
this.score[1]=yw;
this.score[2]=sx;
this.score[3]=com;
this.score[4]=ty;
this.zongfen=0;
for(i=0;i<=4;i++)
this.zongfen=this.zongfen+this.score[i];
this.xm=name;
this.xh=num;
}
Student(Student a)
{
int i;
this.xm=a.xm;
this.xh=a.xh;
score=new float[5];
this.score[0]=a.score[0];
this.score[1]=a.score[1];
this.score[2]=a.score[2];
this.score[3]=a.score[3];
this.score[4]=a.score[4];
this.zongfen=0;
for(i=0;i<=4;i++)
this.zongfen=this.zongfen+this.score[i];
}
}
public class Sort
{
void paixu(Student[] stu)
{
int i,j,k;
i=stu.length;
for(k=1;k<=i;k++)
for(j=0;j<=i-2;j++)
{
if(stu[j].zongfen<stu[j+1].zongfen)
{
Student temp=new Student(stu[j]);
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
for(k=0;k<=i-1;k++)
System.out.println(stu[k].xm+"\t"+stu[k].xh+"\t"+stu[k].zongfen);
}
public static void main(String[] args)
{
Student[]
starray=new Student[9];
Sort st=new Sort();
starray[0]=new Student("黎明",1,81,89,99,98,87);
starray[1]=new Student("张力",2,89,90,95,80,90);
starray[2]=new Student("王英",3,91,77,88,95,78);
starray[3]=new Student("赵锐",4,79,84,95,93,96);
starray[4]=new Student("周密",5,95,92,98,99,93);
starray[5]=new Student("周川",6,78,88,85,86,80);
starray[6]=new Student("孙康",7,91,85,94,82,88);
starray[7]=new Student("郑重",8,90,92,94,90,95);
starray[8]=new Student("胡琴",9,75,85,87,94,90);
st.paixu(starray);
}
}