Didart

Even and Odd Subtraction

Sep 30th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class EvenAndOddSubtraction {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String[] input = scanner.nextLine().split(" ");
  9.  
  10.         int[] numbers = Arrays.stream(input).mapToInt(element -> Integer.parseInt(element)).toArray();
  11.  
  12.         int evenSum = 0;
  13.         int oddSum = 0;
  14.  
  15.         for (int number : numbers) {
  16.             if (number % 2 == 0) {
  17.                 evenSum += number;
  18.                 System.out.println();
  19.             } else {
  20.                 oddSum += number;
  21.             }
  22.         }
  23.         System.out.println(evenSum - oddSum);
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment