The solution reads the user input from the standard input as a string. Then iterates through each character, converts them to integers and add it to the right sum depending on if digit is even or odd.
Reema K.
asked 06/01/20solution for this problem
Sum of Odd and Even Digits
Problem Statement :
Write a java program to calculate the sum of odd and even digits in a number. The input consists of a single integer 'n' which corresponds to the given number.The output must display the sum of odd numbers and even numbers.
Problem Constraints:
The datatype of integer must be long.
The file name must be Main.java
Sample Input and Output :
Enter the number
3924209420352
The sum of the odd digits are 29
The sum of the even digits are 16
1 Expert Answer
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.