Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekciq;
- import java.util.Arrays;
- import java.util.Scanner;
- public class LargestThreeNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // Read a line of integers separated by space
- String inputLine = scanner.nextLine();
- // Split the input line into an array of strings
- String[] numbersAsString = inputLine.split(" ");
- // Convert the array of strings to an array of integers
- int[] numbers = Arrays.stream(numbersAsString)
- .mapToInt(Integer::parseInt)
- .toArray();
- // Sort the array of integers in descending order
- Arrays.sort(numbers);
- for (int i = 0; i < Math.min(numbers.length, 3); i++) {
- System.out.print(numbers[numbers.length - i - 1] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement