展开全部
import java.util.Scanner;
interface getGrade{
public void finGrade();
}
class First implements getGrade{
int a[];
public First(){}
public First(int grade[]){
a=grade.clone();
}
public void finGrade(){
int sum;
for (int i=0;i<=4;i++)
{
sum=sum+a[i];
}
int num;
num=sum/5;
System.out.println("平均636f70793231313335323631343130323136353331333335313736成绩为:"+num);
}
};
class Second implements getGrade{
int a[];
public Second(){}
public Second(int grade[]){
a=grade.clone();
}
public void finGrade(){
int j,k,t;
for (j=1;j<5;j++)
for (k=0;k<5-j;k++)
if (a[k]>a[k+1])
{
t=a[k];
a[k]=a[k+1];
a[k+1]=t;
}
a[0]=0;
a[4]=0;
int sun;
for (int i=0;i<=4;i++)
{
sun=sun+a[i];
}
int nun;
nun=sun/3;
System.out.println("平均成绩为:"+nun);
System.out.println("(去掉一个最高分和一个最低分)");
}
};
public class exer4 {
public static void main (String args[]){
System.out.println("请依次输入评委所给的分数");
System.out.println("(默认为五个评委)");
int a[] = new int [5];
Scanner reader = new Scanner(System.in);
int x = reader.nextInt();
int i;
for (i=0;i<=4;i++)
a[i]=x;
First fir=new First(a);
Second sec=new Second(a);
fir.finGrade();
sec.finGrade();
}
}楼上设置全局变量是个方法,这样进行参数传递也是一种方法。