Created
February 2, 2018 23:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
(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