Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Scanner;
- public class TopInteger {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayList<Integer> topInts = new ArrayList<Integer>();
- int[] input = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- boolean isTopInt = true;
- for (int i = 0; i < input.length - 1; i++) {
- for (int j = i + 1; j < input.length; j++) {
- int numberToCheck = input[i];
- int checkAgainst = input[j];
- if (numberToCheck<= checkAgainst) {
- isTopInt = false;
- continue;
- }
- }
- if (isTopInt) {
- topInts.add(input[i]);
- }
- isTopInt = true;
- }
- topInts.add(input[input.length - 1]);
- for (Integer topInt : topInts) {
- System.out.print(topInt + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement