Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab5EvenOddSubtraction {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String[] inputNumber = input.split(" ");
- int[] array = new int[inputNumber.length];
- int evenSum = 0;
- int oddSum = 0;
- for (int i = 0; i < array.length ; i++) {
- array[i]=Integer.parseInt(inputNumber[i]);
- }
- for (int i : array) {// for each loop
- if (i % 2==0){
- evenSum+=i;
- }else {
- oddSum += i;
- }
- }
- int subtraction = evenSum - oddSum;
- System.out.println(subtraction);
- }
- }
- /* Write a program that calculates the difference between the sum of the even
- and the sum of the odd numbers in an array.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement