Write a program that generates one hundred random integers between 0 and 9 and displays the count for each number. Your program must have method that returns the counts for each number.
Hint: Use (int)(Math.random() * 10) to generate a random integer between 0 and 9. Use an array of ten integers, say count, to store the counts for the number of 0’s, 1’s, …, 9’s.

9 Years
Discussion Span
Last Post by ejosiah

Your project description literally tells you exactly what you need to do. Create an array of ten integers. Every time you see a 0, increment array[0]. Every time you see a 1, increment array[1]. Etc.


I'm not helping you by doing this but I just wanted to have some fun so here's your solution:

public class RandomNumbers {
	public static void main(String[] args) {
		int[] frequency = new int[10];
		for(int i = 0; i < 100; i++){
			int randomNumber = generate();
	private static int generate(){
		return (int)(Math.random() * 10);
	private static void printArray(int[] array){
		for(int i = 0, size = array.length; i < size; i++ ){
			System.out.println(i + " frequence -> " + array[i]);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.