0
Input any 10 numbers and print the sum of odd and even numbers using scanner class and without arrays
7 Respuestas
+ 5
Show your attempt 🙂
+ 5
Martin Taylor yaa truee 👏👏😅👌👌
That's why I asked for his attempt 🙃
+ 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!
+ 2
I hope this will help
https://code.sololearn.com/c0s7F98ShPp7/?ref=app
+ 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
+ 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);
}
}