Advertisement
Krassi_Daskalova

TopIntegers

Jun 15th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class TopInteger {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. ArrayList<Integer> topInts = new ArrayList<Integer>();
  9. int[] input = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  10.  
  11. boolean isTopInt = true;
  12.  
  13. for (int i = 0; i < input.length - 1; i++) {
  14.  
  15. for (int j = i + 1; j < input.length; j++) {
  16. int numberToCheck = input[i];
  17. int checkAgainst = input[j];
  18.  
  19. if (numberToCheck<= checkAgainst) {
  20. isTopInt = false;
  21. continue;
  22. }
  23. }
  24. if (isTopInt) {
  25. topInts.add(input[i]);
  26. }
  27. isTopInt = true;
  28. }
  29.  
  30. topInts.add(input[input.length - 1]);
  31.  
  32. for (Integer topInt : topInts) {
  33. System.out.print(topInt + " ");
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement