Advertisement
Guest User

Untitled

a guest
Nov 24th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public class R727 {
  2.     public static void main(String[] args) {
  3.         int[] values = {1, 2, 3, 4, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8};
  4.         int popular = values[0];
  5.         int popularCount = 0;
  6.         int tempCount = 0;
  7.         for(int i = 0; i < values.length; i++) {
  8.             tempCount = 1;
  9.             for(int j = i + 1; j < values.length; j++) {
  10.                 if(values[j] == values[i]) {
  11.                     tempCount++;
  12.                 }
  13.             }
  14.             if(tempCount > popularCount) {
  15.                 popular = values[i];
  16.                 popularCount = tempCount;
  17.             }
  18.         }
  19.         System.out.println("The number " + popular + " appears " + popularCount + " times.");
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement