# How to Return Single-Digit Counts after Numbers are Randomly Generated (Java,Arrays)

I have written a program that generates 100 random integers between

0 and 9 and displays the count for each number.

int[] counts = new int[10]; // Array of ten integers

// Store the counts of 100 random numbers

for (int i = 1; i <= 100; i++) {

counts[(int)(Math.random() * 10)]++;

}

// Display the results

System.out.println("Count for each number between 0 and 9:");

for (int i = 0; i < counts.length; i++) {

System.out.println(i + "s: " + counts[i]);

}

Now I am being asked to write a program that generates 1000 random integers between 0 and 99, and...

By: StackOverFlow - Wednesday, 7 November

# Related Posts

- Older News
- How to find the average of randomly generated numbers in JAVA StackOverFlow (Yesterday) - I am randomly generating a GPA for a student in the class. In the app I repeat the step 8 times, for a total of 8 different GPA's. At the...
- Big numbers multiplication algorithm doesn't always work StackOverFlow (2 days ago) - I'm trying to create a function that reads two positive natural numbers from an input file and, once calculated, writes their product in an output file.The numbers are "big numbers",...
- How to compare arrays in java method and return a new array? StackOverFlow (2 days ago) - How can i compare two arrays(one is filled with random numbers and the second array is filled by the user input) how do i save the matched numbers to a...