Advertisement
ultravibez

Really final mostCommon

Sep 7th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1.     public static int mostCommonNum(int[] arr) {
  2.         int mostCommon = arr[0];
  3.         int counter = 0;
  4.         int tempCounter = 0;
  5.         for (int i = 0; i < arr.length - 1; i++) {
  6.             if (arr[i] == arr[i + 1]) {
  7.                 counter++;
  8.                 System.out.println(arr[i] + "," + arr[i + 1]);
  9.                 System.out.println(counter);
  10.             }
  11.             if (tempCounter < counter) {
  12.                 tempCounter = counter;
  13.                 mostCommon = arr[i];
  14.             }
  15.             if (arr[i] != arr[i + 1]) {
  16.                 counter = 0;
  17.             }
  18.         }
  19.         return mostCommon;
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement