Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SoftUni {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter your array here: ");
- String[] stringArr = sc.nextLine().split(" ");
- int[] arr = new int[stringArr.length];
- for(int i = 0;i<arr.length;i++){
- arr[i] = Integer.parseInt(stringArr[i]);
- }
- int n,j;
- int maxCount = 0;
- int currentCount = 0;
- int startIndex = 0;
- int endIndex = 0;
- for(n = 0;n<arr.length-1;n++){
- currentCount = 0;
- for(j = n+1;j<arr.length;j++){
- if(arr[n] == arr[j]){
- currentCount++;
- }
- }
- if(currentCount > maxCount){
- maxCount = currentCount;
- startIndex = n;
- endIndex = n + maxCount;
- }
- }
- for(int k = startIndex;k<=endIndex;k++){
- System.out.print(arr[k] + " ");
- }
- }
- }
Add Comment
Please, Sign In to add comment