Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created February 2, 2018 23:24
Show Gist options
  • Save gitaficionado/d764e92434621bee5b7e525c0f195a5b to your computer and use it in GitHub Desktop.
Save gitaficionado/d764e92434621bee5b7e525c0f195a5b to your computer and use it in GitHub Desktop.
Write a program that generates 100 random integers between 0 and 9 and displays the count for each number.
/*
(Count single digits) Write a program that generates 100 random integers between
0 and 9 and displays the count for each number. (Hint: Use an array of ten integers,
say counts, to store the counts for the number of 0s, 1s, . . . , 9s.)
*/
public class CountSingleDigits {
public static void main(String[] args) {
int[] ________ = new int[___];
for (int i = 0; __ < _____; i++) {
int value = (int)(Math.____________() * 10);
counts[value]++;
}
for (int i = 0; i < counts.length; i++) {
System.out.println("Count for " + i + " is " + _______[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment