Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- int arr[] = {1,2,3,4,5,6,6,6,7,2,2};
- int max[] = new int[2];
- int tmp[] = new int[2];
- max[0] = tmp[0] = arr[0];
- max[1] = tmp[1] = 1;
- for (int i=1;i<arr.length;i++){
- if(arr[i] == tmp[0]) tmp[1]++;
- else{
- if(tmp[1] >= max[1]){
- max[0] = tmp[0];
- max[1] = tmp[1];
- }
- tmp[0] = arr[i];
- tmp[1] = 1;
- }
- }
- if(tmp[1] >= max[1]){
- max[0] = tmp[0];
- max[1] = tmp[1];
- }
- System.out.println("Max " +max[1]+ " equal elements of "+max[0]+"s");
- }
Advertisement
Add Comment
Please, Sign In to add comment