Created
January 7, 2010 20:17
-
-
Save johnhmj/271537 to your computer and use it in GitHub Desktop.
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
import java.io.*; | |
//import java.util.Scanner; | |
public class Main { | |
// Start of main | |
public static void main(String[] args) { | |
PrintStream jout = new PrintStream(System.out); | |
// Scanner jin = new Scanner(System.in); | |
int MAX_LENGTH = 100, MAX_NUMBER = 10; | |
// build rn for generating random numbers | |
int[] rn = new int[MAX_LENGTH]; | |
// build count for counting rn | |
int[] count = new int[MAX_NUMBER]; | |
// generate 100 numbers | |
for (int i = 0; i < MAX_LENGTH; i++) { | |
rn[i] = (int) (Math.random() * MAX_NUMBER + 1); | |
count[rn[i] - 1]++; | |
} | |
// print count | |
for (int i = 0; i < count.length; i++) { | |
jout.printf("Number %d: %d times.\n", (i + 1), count[i]); | |
} | |
}// End of main | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment