Calculate average in java

后端 未结 10 2147
悲哀的现实
悲哀的现实 2020-12-11 07:49

EDIT: Ive written code for the average, but i dont know how to make it so that it also uses ints from my args.length rather than the array

I need to

10条回答
  •  悲哀的现实
    2020-12-11 08:07

    public class MainTwo{
        public static void main(String[] arguments) {
            double[] Average = new double[5];
            Average[0] = 4;
            Average[1] = 5;
            Average[2] = 2;
            Average[3] = 4;
            Average[4] = 5;
            double sum = 0;
            if (Average.length > 0) {
                for (int x = 0; x < Average.length; x++) {
                    sum+=Average[x];
                    System.out.println(Average[x]);
                }
                System.out.println("Sum is " + sum);
                System.out.println("Average is " + sum/Average.length);
          }
       }
    }
    

提交回复
热议问题