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...

Read More »

By: StackOverFlow - Wednesday, 7 November

Related Posts