publicclassxscj2{publicstaticdoublea1(doublea[]){doubleresult=0;inti=0;while(i
public class xscj2
{
public static double a1(double a[])
{
double result=0;int i=0;
while (i
result+=a[i++];
return result/a.length;
}
public static double b1(double b[])
{
double result=0;int i=0;
while (i
result+=b[i++];
return result/b.length;
}
public static double c1(double c[])
{
double result=0;int i=0;
while (i
result+=c[i++];
return result/c.length;
}
public static double d1(double d[])
{
double result=0;int i=0;
while (i
result+=d[i++];
return result/d.length;
}
public static void main(String[] args)
{
double a2;
double b2;
double c2;
double d2;
double a[]={90,85,66,51,69,78,88,94};
double b[]={68,88,81,90,65,74,64,46};
double c[]={68,90,85,88,68,70};
double d[]={60};
a2=a1(a);
b2=b1(b);
c2=c1(c);
d2=d1(d);
现在能不能想个办法只用一个方法a1(a),把数组a,b,c,d的值全部求出来并赋给a2,b2,c2,d2,
就是说能不能不把:
public static double a1(double a[])
{
double result=0;int i=0;
while (i
result+=a[i++];
return result/a.length;
}
这方法写4遍求出来!
展开