我正在尝试实现两种方法:main
方法和另一种方法。 side方法通过数学计算得到Array的平均值,该Array位于main方法本身。然后它将它返回到main方法。
import java.util.*;
public class ArrayAverageDouble
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double average=0;
int i=0;
double sum=0;
int size = 0;
System.out.println("What size do you want the Array: ");
size = sc.nextInt();
double arrayDouble[] = new double[size];
for (i = 0; i < arrayDouble.length; i++)
{
System.out.println("Enter a number");
arrayDouble[i]=sc.nextDouble();
}
System.out.println("The average of ' arrayDouble ' is: " + average);
sc.close();
}
private static void avgInt(double[] arrayDouble)
{
average = ?
return average;
}
}
答案 0 :(得分:0)
private static double average(double[] arrayDouble) {
double total = 0;
for(double value : arrayDouble) {
total += value;
}
return total / arrarDouble.lenght;
}