Advertisement
SensaBG

petazadacha2

Aug 28th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package ArraysExercise;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class TopIntegers {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int[] numbers = Arrays.stream(scanner.nextLine().split(" "))
  11.                               .mapToInt(Integer::parseInt)
  12.                               .toArray();
  13.  
  14.         for (int i = 0; i < numbers.length - 1; i++) {
  15.             int currentNum = numbers[i];
  16.             boolean isBigger = false;
  17.  
  18.             for (int j = i + 1; j <= numbers.length - 1; j++) {
  19.                 int compareNum = numbers[j];
  20.                 if (currentNum <= compareNum) {
  21.                     isBigger = true;
  22.                     break;
  23.                 }
  24.             }
  25.  
  26.             if (!isBigger) {
  27.                 System.out.print(currentNum + " ");
  28.             }
  29.         }
  30.         System.out.println(numbers[numbers.length - 1]);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement