Skip to content

Instantly share code, notes, and snippets.

@johnhmj
Created January 7, 2010 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhmj/271537 to your computer and use it in GitHub Desktop.
Save johnhmj/271537 to your computer and use it in GitHub Desktop.
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