Advertisement
veronikaaa86

03. Sum Even Numbers

Sep 30th, 2021
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package arrays;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class P03SumEvenNumbers {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String inputLine = scanner.nextLine();
  11.  
  12. int[] numArr = Arrays
  13. .stream(inputLine.split(" "))
  14. .mapToInt(Integer::parseInt)
  15. .toArray();
  16.  
  17. int sum = 0;
  18. for (int i = 0; i < numArr.length; i++) {
  19. if (numArr[i] % 2 == 0) {
  20. sum += numArr[i];
  21. }
  22. }
  23.  
  24. System.out.println(sum);
  25. }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement