对成绩进行排序,查找最大值,最小值,平均值(oop)。
packagescare;
public classscare {
staticint i=0;
staticint s[]={80,60,40,50,30,99,70,20,65,79,1};
publicstatic void main(String arg[]){
scare test=new scare();
test.display();
test.resort();
test.getmin();
test.getmax();
test.average();
}
public voiddisplay(){
inti;
System.out.print("学生的成绩为:");
for(i=0;i<s.length;i++)
System.out.print(+s[i]+"");
}
public voidsort(){
intj=0;
inttmp=0;
//System.out.print("从小到大排序:");
for(i=0;i<s.length;i++){
for(j=0;j<s.length-i-1;j++){
if(s[j]>s[j+1]){
tmp=s[j+1];
s[j+1]=s[j];
s[j]=tmp;
}
}
}
}
//冒泡排序
public voidresort(){
sort();
System.out.print("\n成绩从小到大排序:");
for(i=0;i<s.length;i++)
System.out.print(+s[i]+"");
}
public voidgetmin(){
sort();
System.out.println("\n成绩的最小值:"+s[0]);
}
public voidgetmax(){
sort();
System.out.println("成绩的最大值:"+s[s.length-1]);
}
public voidaverage(){
intaverage=0;
intsum=0;
for(i=0;i<s.length;i++)
{
sum=sum +s[i];
}
average=sum/s.length;
System.out.println("成绩的平均值:"+average);
}
}
实验结果