import java.util.Scanner;
public interface ComputerAverage {
double average(double num[]);
}
class School implements ComputerAverage{
public double average(double num[]){
int i,b=num.length;
double are=0;
for(i=0;i
are+=num[i];
}
if(b>0)
are=are/num.length;
return are;
}
}
class Gymnastics implements ComputerAverage {
public double average(double num[]){
int j,i, b=num.length;
double are=0,tempt=0;
for(i=0;i
for(j=i;j
if(num[j]
tempt=num[i];
num[i]=num[j];
num[j]=tempt;
}
}
for(i=1;i are=num[i]+are; are=are/(b - 2); return are; } } class Mainclass{ public static void main(String[] args){ double score[]={9.21, 8.53, 8.65, 9.50, 9.88, 8.76, 9.46, 9.78}; double scor1[]={80.5, 88, 98.5, 99, 78, 88 ,85 ,81.6, 92.5}; ComputerAverage computer; computer=new Gymnastics(); double r=computer.average(scor1); System.out.printf("体 *** 的平均分:%.2f\n",r); computer=new School(); r=computer.average(scor1); System.out.printf("班级的平均分:%.2f\n",r); } } 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)