Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] numbers = Arrays
- .stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .toArray();
- int evenSum = 0, oddSum = 0;
- for (int n : numbers) {
- if (n % 2 == 0) {
- evenSum += n;
- } else {
- oddSum += n;
- }
- }
- System.out.println(evenSum - oddSum);
- }
- }
- OR:
- import java.util.Scanner;
- import java.util.Arrays;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] numbers = Arrays
- .stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .toArray();
- int evenSum = Arrays.stream(numbers).filter(e -> e % 2 == 0).sum();
- int oddSum = Arrays.stream(numbers).filter(e -> e % 2 == 1).sum();
- System.out.println(evenSum - oddSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement