Here is a program that reads unordered numbers from the standard input, converts them to numbers, sorts and multiplies by two. Unfortunately, the sorting order is not preserved when displaying numbers. Please, fix it somehow!
Parallel streams
Fix the sorting order
Report a typo
Sample Input 1:
4 2 3 0 1Sample Output 1:
0
2
4
6
8Write a program in Java 17
import java.util.Arrays;
import java.util.Scanner;
class ParallelMapping {
private static final Scanner SCANNER = new Scanner(System.in);
public static void main(String[] args) {
Arrays.stream(SCANNER.nextLine().split("\\s+"))
.map(Integer::parseInt)
.sorted()
.map(n -> n * 2)
.parallel()
.forEach(System.out::println);
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.