daily pastebin goal
13%
SHARE
TWEET

3. Sum Even Numbers

a guest Feb 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class SumEvenNumbers {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int [] numbers = Arrays.stream(scanner.nextLine().split(" ")).
  9.                 mapToInt(e->Integer.parseInt(e)).toArray();
  10.  
  11.         int sum = 0;
  12.  
  13.         for (int number:numbers) {
  14.             if (number%2==0){
  15.                 sum +=number;
  16.             }
  17.         }
  18.         System.out.println(sum);
  19.     }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top