Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MostFrequent{
- public static void main(String[] args) {
- Scanner in= new Scanner(System.in);
- int N = in.nextInt();
- int[] a = new int[N];
- for(int i=0;i<N;i++){
- a[i]=in.nextInt();
- }
- int maxLength = 1;
- int currentLength = 1;
- int mostFrequentNumber = a[0];
- for (int i = 0; i < a.length; i++) {
- int currentNumber = a[i];
- for (int j = i+1; j < a.length; j++) {
- if(currentNumber == a[j]){
- currentLength++;
- }
- }
- if(currentLength > maxLength){
- maxLength = currentLength;
- mostFrequentNumber = currentNumber;
- }
- currentLength = 1;
- }
- System.out.println(mostFrequentNumber+"("+maxLength+"times)");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement