Question: the question was to create a [3][3] double array of random integers bewteen 40 and 55.also find sum and average and count how many times
the question was to create a [3][3] double array of random integers bewteen 40 and 55.also find sum and average and count how many times each numbers appeared and store the counts in an called array count[]. all this is done by me.
but another question which i can't answer is find the highest random numbers which appared. and also print random array upside down
here is acode which i have done so far. and it works for printing double arrayis, finding sum , average, and how many times each numbers apperaed.
import java.util.*; class Statistics //class name { public static void main( String [] args ) { Random random = new Random(); //declare random int[][] array = new int[3][3]; //declare 2d array int[] count = new int[16]; //declare count for( int i = 0 ; i < array.length ; i++ ) { for ( int j = 0 ; j < array[i].length ; j++ ) { array[i][j] = random.nextInt(15)+40; } } // storing inital value to zero to all numbers for(int i=0;i<16;i++){ count[i] = 0; } // getting count of each element in random numbers for( int i = 0 ; i < array.length ; i++ ) { for ( int j = 0 ; j < array[i].length ; j++ ) { count[array[i][j]-40]++; } } for( int[] a : array ) { System.out.println( Arrays.toString( a )); } int total = 0; for (int row = 0; row < array.length; row++) { for (int col = 0; col < array[row].length; col++) total += array[row][col]; } System.out.println("The total of the elements is " + total); //total System.out.println(" The average of the elements is " + total/16); //average // printing each digit count System.out.println("Count of each number generated: "); for(int i=0;i<16;i++){ System.out.println((40+i)+" is repeated "+count[i]+" times"); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
