Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int sum = Arrays // "1 2 3 4 5 6 7 8 9"
- .stream(scanner.nextLine().split(" ")) // ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
- .mapToInt(Integer::parseInt) // [1, 2, 3, 4, 5, 6, 7, 8, 9]
- .filter(x -> x % 2 == 0) // [2, 4, 6, 8]
- .sum(); // 2 + 4 + 6 + 8
- System.out.println(sum); // 20
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement