SHARE
TWEET

Untitled

shniaga Feb 7th, 2019 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ArraysExercise;
  2.  
  3. import java.lang.reflect.Array;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7. public class MaxSequenceOfEqualElements {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  12.  
  13.         int counter = 0;
  14.         int currentCounter = 0;
  15.         String currentSequence = "";
  16.         String sequence = "";
  17.  
  18.         for (int i = 0; i < numbers.length - 1; i++) {
  19.             if (currentCounter > counter) {
  20.                 counter = currentCounter;
  21.                 sequence = currentSequence + numbers[i - 1];
  22.  
  23.             }
  24.             currentCounter = 0;
  25.             currentSequence = "";
  26.  
  27.             for (int j = i + 1; j <= numbers.length-1; j++) {
  28.                 if (numbers[i] == numbers[j]) {
  29.                     currentCounter++;
  30.                     currentSequence += numbers[i] + " ";
  31.                 } else {
  32.                     break;
  33.                 }
  34.             }
  35.         }
  36.         if (sequence.equals("")) {
  37.             System.out.println(numbers[0]);
  38.         }
  39.  
  40.         System.out.println(sequence);
  41.  
  42.  
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top