Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] tally = new int[]{2, 2, 1, 1, 1, 1, 4, 1, 1, 4};
- int[] rate = new int[5]; // defaults to zero
- // rate[n] will be the frequency of value n
- // so n should be 0 to 4
- for (int index = 0; index < tally.length; index++) {
- int value = tally[index];
- if (value > -1 && value < rate.length) {
- rate[value]++;
- }
- }
- for (int index = 0; index < rate.length; index++) {
- System.out.println(index + "\t" + rate[index]);
- }
Advertisement
Add Comment
Please, Sign In to add comment