0

Input any 10 numbers and print the sum of odd and even numbers using scanner class and without arrays

25th Aug 2020, 4:32 AM
prakriti
7 Antworten
+ 5
Show your attempt 🙂
25th Aug 2020, 4:34 AM
Namit Jain
Namit Jain - avatar
+ 5
Martin Taylor yaa truee 👏👏😅👌👌 That's why I asked for his attempt 🙃
25th Aug 2020, 12:36 PM
Namit Jain
Namit Jain - avatar
+ 2
Hint: - Prepare two int variables, <sumOfEven> and <sumOfOdd>. Initialize them by zero. - Setup a loop running ten times. - In loop body, read a number; If it's even, add the number to <sumOfEven>, Else, if it's odd, add the number to <sumOfOdd>. - Print <sumOfEven> and <sumOfOdd>. Mission accomplished!
25th Aug 2020, 6:13 AM
Ipang
25th Aug 2020, 8:57 AM
Jkim Avatar
Jkim Avatar - avatar
+ 2
The moment coding becomes an adventure to explore every bit of the journey you can rather than a competition to finish the journey first, Thats wen you'll realize that you cant be tricked into doing what you love doing coz you'll always do it no matter what I saw it as a challenge you saw it as somebody's work not ur own There's always a legend falling every minute too you know
25th Aug 2020, 2:16 PM
Jkim Avatar
Jkim Avatar - avatar
+ 1
Use loop for input ten numbers and take one variable for sum =0 use two conditions For even Numbers use if(number%2==0) Then sum+=number Print even number Same for odd number use if(number%!==0) then print sum of odd number i use array see this example if u want to input from user then u need loop . import java.io.*; class EvenOddSum {     public static void main(String args[])     {         int arr[] = { 1, 2, 3, 4, 5, 6,7,8,9,10 };         int even = 0, odd = 0;         // Loop to find even, odd sum         for (int i = 0; i < arr.length; i++) {             if (i % 2 == 0)                even += arr[i];             else               odd += arr[i];         }         System.out.println("Even index positions sum: " + even);         System.out.println("Odd index positions sum: " + odd);     } }
25th Aug 2020, 7:57 AM
A S Raghuvanshi
A S Raghuvanshi - avatar