# 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
- Given a non-negative int n, compute recursively (no loops) the count of the occurrences of 8 StackOverFlow (Today) - Hi can you please help me with my new assignment on codingbat , its codingbat-recursion-count8Given a non-negative int n, compute recursively (no loops) the count of the occurrences of 8...
- Given a bunch of integer numbers, please output all combination of all possible numbers by using plus operation only StackOverFlow (Yesterday) - Given a bunch of integer numbers, please output all combination of all possible numbers by using plus operation only.For example, [10, 20] => [10, 20, 30][1, 2, 3] => [1,...
- Java histogram from random generated numbers StackOverFlow (Yesterday) - Hi guys, I am playing with and learning a bit of java, so I'm really a newbie ... My problem is - I am generating 5 random numbers from 1...
- Count repetitions in array in java StackOverFlow (2 days ago) - I know that similar questions have been asked and I have researchedmany websites. I have tried to use some of the answers but my code isstill not working.I am going...
- How can I get the printed 1 digit number rather than the original number I typed in? StackOverFlow (3 days ago) - Hello this is my first post, sorry if I asked this question wrong, however, I am also new to Java programming, I am trying to find the largest digit and...
- Merge two sorted arrays in java StackOverFlow (3 days ago) - I know that similar questions have been asked and I have researchedmany websites. I have tried to use some of the answers but my code isstill not working.I am going...
- Scratch Card - Decimal to Octal Conversion. StackOverFlow (3 days ago) - I need help in solving this:A scratch card consists of 4 sets of 5 digits (20 digits in total) e.g. [10006-12342-00081-99993] which are printed separated by a space or a...