Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.*;
- public class frequent {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String input = scan.nextLine();
- input = input.replaceAll("\\s+", " ");
- String[] arr = input.split(" ");
- int[] numbers = new int[arr.length];
- for(int i =0;i<arr.length;i++){
- numbers[i] = Integer.parseInt(arr[i]);
- }
- System.out.println(mostFrequent(numbers,numbers.length));
- }
- static int mostFrequent(int numbers[], int n) {
- Arrays.sort(numbers);
- int counter = 0;
- int max = Integer.MIN_VALUE;
- for(int i = 0;i<numbers.length;i++){
- counter++;
- if(i == numbers.length - 1){
- if(max < counter){
- max = counter;
- }
- break;
- }
- if(numbers[i] != numbers[i+1]){
- if(max < counter){
- max = counter;
- }
- counter = 0;
- }
- }
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment