mardi 12 novembre 2019

How do I calculate the average of 10 random numbers in an array and then list the ones that are smaller than the average in Java? [duplicate]

So I'm trying to write a program for someone that reads 10 random numbers into an array. I want it to read and compute the average of the 10 numbers then go back and list the numbers that are smaller than the average. I was told to use decimal division. Heres what I have-

        Random rd = new Random();
        int[] array = new int[10];

        for(int shelf = 0; shelf < 10; shelf++)
        {
            array[shelf] = rd.nextInt(10 - 1);
            System.out.println(array[shelf]);
        }

It currently just prints the 10 indices. I need it to find the average using decimal division and then print out all of the numbers that are below the average. Please use meaningful variable names.




Aucun commentaire:

Enregistrer un commentaire