Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int mostCommonNum(int[] arr) {
- int mostCommon = arr[0];
- int counter = 0;
- int tempCounter = 0;
- for (int i = 0; i < arr.length - 1; i++) {
- if (arr[i] == arr[i + 1]) {
- counter++;
- System.out.println(arr[i] + "," + arr[i + 1]);
- System.out.println(counter);
- }
- if (tempCounter < counter) {
- tempCounter = counter;
- mostCommon = arr[i];
- }
- if (arr[i] != arr[i + 1]) {
- counter = 0;
- }
- }
- return mostCommon;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement