+ 1

How to write a program dat reads a set of integers then displays the sum of all even nos. & sum of all odd nos.

Example Output: Enter Series of Numbers 2 6 89 45 22 3 90 The sum of Even Numbers is: 120 The Sum of Odd Numbers is: 137

16th Aug 2018, 5:52 AM
John Kevin Laurencio
John Kevin Laurencio - avatar
3 Antworten
+ 10
John Kevin Laurencio public class Program { public static void main(String[] args) { int []arr={25,35,44,99,88,2}; int sum_odd=0,sum_even=0; for(int i=0;i<arr.length;i++) if(arr[i]%2!=0)sum_odd+=arr[i]; else sum_even+=arr[i]; System.out.println(sum_odd); System.out.println(sum_even); } }
16th Aug 2018, 7:05 AM
Lương Văn Tuấn
Lương Văn Tuấn - avatar
+ 2
You have to post your try (eg. your code) because this seem an assignement and hardly you will find someone that make it for you
16th Aug 2018, 6:32 AM
KrOW
KrOW - avatar
0
im a noob in programming. pls help
16th Aug 2018, 6:05 AM
John Kevin Laurencio
John Kevin Laurencio - avatar