Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this assignment. Using very basic knowledge of Java as I am onl

ID: 3865194 • Letter: I

Question

I need help with this assignment.

Using very basic knowledge of Java as I am only a few Chapters in to my intro to Java Class.

1. Create an array of 1000 integers.

2. Populate the array with random numbers between 1 and 100.

3. Calculate and print out the average of the numbers in the array. Be accurate to within two decimal points. For example 23.45.

4. Count the number of times each number (1-100) appears in the array and print that information. For example your program should print: The number 1 appears 20 times. The number 2 appears 17 times.

... Feel free to use another array for this step.

Please do not copy and paste from Stack overflow like the last response. I need to study the correct design of this program. Thank You.

Explanation / Answer

RandomNumbersCount.java

import java.util.Random;

public class RandomNumbersCount {

   public static void main(String[] args) {
       //Declaring variables
       int sum=0,count;
       double average;
      
       //Creating the Random Class Object
       Random r = new Random();
      
       //Creating an Integer Array Of size 1000
       int arr[]=new int[1000];
      
       //Populating random numbers between 1-100 into an array
       for(int i=0;i<100;i++)
       {
           //Generating the random number between 1-100
       arr[i]=r.nextInt(100) +1;  
      
       //calculating the sum
       sum+=arr[i];
       }
      
       //calculating the average
       average=(double)sum/100;
      
       //Displaying the average
System.out.printf("Average :%.2f ",average);

//This Nested for loop will count no of occurrences of each number in the array
for(int i=1;i<=100;i++)
{
   count=0;
   for(int j=0;j<arr.length;j++)
   {
       if(i==arr[j])
       {
           count++;
       }
   }
     
   //Displaying the result
   System.out.println(i+" appears "+count+" times");
}
   }

}

____________________

Output:

Average :52.54

1 appears 0 times
2 appears 1 times
3 appears 1 times
4 appears 1 times
5 appears 1 times
6 appears 1 times
7 appears 2 times
8 appears 0 times
9 appears 0 times
10 appears 3 times
11 appears 1 times
12 appears 1 times
13 appears 2 times
14 appears 3 times
15 appears 0 times
16 appears 0 times
17 appears 2 times
18 appears 0 times
19 appears 0 times
20 appears 0 times
21 appears 0 times
22 appears 1 times
23 appears 3 times
24 appears 0 times
25 appears 0 times
26 appears 2 times
27 appears 2 times
28 appears 1 times
29 appears 1 times
30 appears 1 times
31 appears 1 times
32 appears 0 times
33 appears 0 times
34 appears 2 times
35 appears 1 times
36 appears 1 times
37 appears 0 times
38 appears 2 times
39 appears 1 times
40 appears 1 times
41 appears 1 times
42 appears 2 times
43 appears 0 times
44 appears 1 times
45 appears 0 times
46 appears 0 times
47 appears 1 times
48 appears 0 times
49 appears 1 times
50 appears 0 times
51 appears 2 times
52 appears 3 times
53 appears 0 times
54 appears 1 times
55 appears 0 times
56 appears 3 times
57 appears 0 times
58 appears 0 times
59 appears 1 times
60 appears 2 times
61 appears 1 times
62 appears 0 times
63 appears 2 times
64 appears 1 times
65 appears 1 times
66 appears 1 times
67 appears 1 times
68 appears 0 times
69 appears 0 times
70 appears 0 times
71 appears 1 times
72 appears 2 times
73 appears 1 times
74 appears 1 times
75 appears 0 times
76 appears 1 times
77 appears 0 times
78 appears 1 times
79 appears 1 times
80 appears 2 times
81 appears 4 times
82 appears 2 times
83 appears 1 times
84 appears 1 times
85 appears 0 times
86 appears 0 times
87 appears 3 times
88 appears 0 times
89 appears 1 times
90 appears 1 times
91 appears 2 times
92 appears 1 times
93 appears 1 times
94 appears 2 times
95 appears 2 times
96 appears 2 times
97 appears 0 times
98 appears 1 times
99 appears 2 times
100 appears 0 times

________________Thank You