waltermilner

Untitled

Oct 28th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1.         int[] tally = new int[]{2, 2, 1, 1, 1, 1, 4, 1, 1, 4};
  2.         int[] rate = new int[5]; // defaults to zero
  3.         // rate[n] will be the frequency of value n
  4.         // so n should be 0 to 4
  5.         for (int index = 0; index < tally.length; index++) {
  6.             int value = tally[index];
  7.             if (value > -1 && value < rate.length) {
  8.                 rate[value]++;
  9.             }
  10.         }
  11.         for (int index = 0; index < rate.length; index++) {
  12.             System.out.println(index + "\t" + rate[index]);
  13.         }
Advertisement
Add Comment
Please, Sign In to add comment