Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hello;
- public class hello {
- public static void main(String[] args) {
- int[] arr = {1, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4};
- int length = 1;
- int maxlength = 0;
- int value = arr[0];
- for (int i = 1; i < arr.length; i++) {
- length = 1;
- while(arr[i] == arr[i-1]){
- length++;
- i++;
- if(i == arr.length)
- break;
- }
- if(maxlength < length){
- maxlength = length;
- value = arr[i - 1];
- }
- }
- System.out.print("{");
- for (int i = 0; i < maxlength - 1; i++) {
- System.out.print(value + ", ");
- }
- System.out.println(value + "}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement