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
6 Answers
+ 3
Saifullah Rahimi
skaltecho already gave you hint. So try self. You have so much time.
+ 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.
+ 2
Saifullah Rahimi Why there is args[0]? Doesn't make sense. And also here you are not adding even numbers.
+ 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
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
0
I Am Groot !
okkk need some more hint logically