Advertisement
CoineTre

JF-LabArrays03.SumEvenNumbers

Jan 18th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lab3SumEvenNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String inputString = scanner.nextLine();
  7.         String[] inputNumbers= inputString.split(" ");
  8.         int[] array = new int[inputNumbers.length];
  9.         int sum = 0;
  10.         for (int i = 0; i < array.length; i++) {
  11.             array[i]=Integer.parseInt(inputNumbers[i]);
  12.             if (array[i] % 2==0){
  13.                 sum+=array[i];
  14.             }
  15.         }
  16.         System.out.println(sum);
  17.     }
  18. }
  19. /*
  20. * Read an array from the console and sum only the even numbers.
  21. * */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement