Question
Write a program that will take an integer and add up each of the numbers digits. You must use a while loop and % to
Write a program that will take an integer and add up each of the numbers digits. You must use a while loop and % to access each of the individual digits. Use / to reduce the number so that you can sum all of the digits.
digit adder shell:
import static java.lang.System.*;
public class DigitAdder { public static int sumDigits( int number ) { int sum=0; return sum; } }
digit adder runner shell:
import static java.lang.System.*;
public class DigitAdderRunner { public static void main( String args[] ) { //add test cases } }
sample data:
234
10000
111
9005
84645
8547
123456789
sample output:
9 is the sum of the digits of 234
1 is the sum of the digits of 10000
3 is the sum of the digits of 111
14 is the sum of the digits of 9005
27 is the sum of the digits of 84645
24 is the sum of the digits of 8547
45 is the sum of the digits of 123456789
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started