public class student
{
String name,id;
double score1,score2,score3;
double sum;
int mingci;
student(){
};
student(String n,String i,double s1,double s2,double s3)
{
name=n;
id=i;
score1=s1;
score2=s2;
score3=s3;
sum=s1+s2+s3;
}
static void selectsort(student a[])
{
for(int i=0;i<a.length;i++)
{
student t=new student();
for(int j=i;j<a.length;j++)
{
if(a[i].sum<a[j].sum)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
}
static void out(student a[])
{
for(int i=0;i<a.length;i++)
System.out.println(" "+"姓名:"+a[i].name+" "+"学号:"+a[i].id+"成绩:"+a[i].score1+" "+a[i].score2+" "+a[i].score3);
}
static void print(student a[])
{
for(int i=0;i<a.length;i++)
a[i].mingci=i+1;
for(int i=0;i<a.length;i++)
{ if(a[i].sum==a[i-1].sum)
{a[i].mingci=a[i-1].mingci;}
else
{a[i].mingci=a[i-1].mingci+1;}
System.out.println(" "+"姓名:"+a[i].name+" "+"学号:"+a[i].id+"总分:"+" "+a[i].sum+"名次:"+a[i].mingci);
}
}
public static void main(String args[])
{
student s[]=new student[5];
s[0]=new student("张三","001",80,90,85);
s[1]=new student("李斯","002",80,80,85);
s[2]=new student("王五","003",70,90,85);
s[3]=new student("赵六","004",80,90,80);
s[4]=new student("李云","005",80,75,85);
System.out.println("排序前");
student.out(s);
student.selectsort(s);
System.out.println("排序后");
student.print(s);
}
}
望远
望远
相关分类