Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab3SumEvenNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String inputString = scanner.nextLine();
- String[] inputNumbers= inputString.split(" ");
- int[] array = new int[inputNumbers.length];
- int sum = 0;
- for (int i = 0; i < array.length; i++) {
- array[i]=Integer.parseInt(inputNumbers[i]);
- if (array[i] % 2==0){
- sum+=array[i];
- }
- }
- System.out.println(sum);
- }
- }
- /*
- * Read an array from the console and sum only the even numbers.
- * */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement