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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!