0

Please help me can anyone code this question in Java ?

You want to take a list of numbers and find the sum of all of the even numbers in the list. Ignore any odd numbers. Task: Find the sum of all even integers in a list of numbers. Input Format: The first input denotes the length of the list (N). The next N lines contain the list elements as integers. Output Format: An integer that represents the sum of only the even numbers in the list. Sample Input: 9 1 2 3 4 5 6 7 8 9 Sample Output: 20

30th Dec 2020, 5:56 PM
Saifullah Rahimi
Saifullah Rahimi - avatar
6 Answers
+ 3
Saifullah Rahimi skaltecho already gave you hint. So try self. You have so much time.
30th Dec 2020, 6:29 PM
A͢J
A͢J - avatar
+ 2
Iterate through the list of numbers and use the Modulus Operator (%) to determine whether or not each number is even. Once you've determined if it's even you can add it to a variable that stores the sum. Example: 10%2=0 The remainder is 0, therefore the number is even. 11%2=1 The remainder is 1, therefore the number is odd.
30th Dec 2020, 6:04 PM
skaltecho
+ 2
Saifullah Rahimi Why there is args[0]? Doesn't make sense. And also here you are not adding even numbers.
30th Dec 2020, 6:21 PM
A͢J
A͢J - avatar
+ 1
I Am Groot ! how i can add even numbers and odd numbers and find the sum of even numbers and ignore the odd numbers can you please write the code
30th Dec 2020, 6:25 PM
Saifullah Rahimi
Saifullah Rahimi - avatar
0
skaltecho public class evenorodd { public static void main(String args[]) { System.out.println("Enter the numbers"); int num = Integer.parseInt(args[0]); if(num%2 ==0) { System.out.println("sum of even numbers",+num); } } } it gives error
30th Dec 2020, 6:11 PM
Saifullah Rahimi
Saifullah Rahimi - avatar
0
I Am Groot ! okkk need some more hint logically
30th Dec 2020, 6:33 PM
Saifullah Rahimi
Saifullah Rahimi - avatar