Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package arrays;
- import java.util.Scanner;
- public class P05EvenAndOddSubtraction {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] arr = scanner.nextLine().split(" ");
- int[] numArr = new int[arr.length];
- for (int i = 0; i < numArr.length; i++) {
- numArr[i] = Integer.parseInt(arr[i]);
- }
- int evenSum = 0;
- int oddSum = 0;
- for (int num : numArr) {
- if (num % 2 == 0) {
- evenSum += num;
- } else {
- oddSum += num;
- }
- }
- // for (int i = 0; i < numArr.length; i++) {
- // if (numArr[i] % 2 == 0) {
- // evenSum += numArr[i];
- // } else {
- // oddSum += numArr[i];
- // }
- // }
- int diff = evenSum - oddSum;
- System.out.println(diff);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement