In: Computer Science
SAMPLE OUTPUT:
1 12 20 11 10 15 17 5 20 8
23 6 4 20 23 15 15 24 4 19
3 10 15 12 8 5 23 24 2 25
2 19 13 3 7 22 17 8 15 9
22 17 3 5 5 20 24 19 21 13
9 1 16 5 16 8 24 11 7 1
19 16 14 11 23 22 23 25 18 3
16 3 10 3 17 15 3 17 15 17
22 16 16 7 15 7 10 22 10 1
21 20 18 4 11 24 24 2 19 12
The average is: 12.51
JAVA Program:
import java.io.*;
import java.util.*;
public class Main
{
public static void populateArray(int []arrayInt){
Random rand=new Random();
for(int i=0;i<100;i++)
arrayInt[i]=rand.nextInt(25)+1;
}
public static void printArray(int []arrayInt){
int i=0;
while(i<100){
System.out.print(arrayInt[i]+" ");
i++;
if(i%10==0)
System.out.println();
}
}
public static float findAverage(int []arrayInt){
float total=0;
for(int i=0;i<100;i++)
total+=arrayInt[i];
return total/100;
}
public static void main(String[] args) {
int[] arrayInt = new
int[100];
populateArray(arrayInt);
printArray(arrayInt);
System.out.printf("The average is:
%.2f",findAverage(arrayInt));
}
}
Output: