Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MostCommonNumber {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = Integer.parseInt(sc.nextLine());
- int[] a = new int[n];
- for (int i = 0; i < a.length; i++) {
- a[i] = Integer.parseInt(sc.nextLine());
- }
- int count = 1, tempCount;
- int popular = a[0];
- int temp = 0;
- for (int i = 0; i < (a.length); i++) {
- temp = a[i];
- tempCount = 0;
- for (int j = 0; j < a.length; j++) {
- if (temp == a[j])
- tempCount++;
- }
- if (tempCount > count) {
- popular = temp;
- count = tempCount;
- }
- }
- System.out.println(popular);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement