$15.00 Java digital root
- From Computer-Science: Object-Oriented-Programming , Computer-Science: Programming-Methods
- Closed, but you can still post tutorials
- Due on Dec. 08, 2012
- Asked on Dec. 04, 2012 at 10:17:04AM
The digital root of an integer is the sum of its digits. If that sum is not a single digit number, the
process is repeated with the sum until a single digit is reached. For example, the digital root of 4726 is 4
+ 7 + 2 + 6 = 19 = 1 + 9 = 10 = 1 + 0 = 1. The iterative version is written as follows:
public static int digitalRoot(int num){
int temp;
while (num > 9){
temp = 0; 2
while (num != 0){
temp += num % 10;
num = num / 10; // or num /= 10;
}
num = temp;
}
return num;
}
Take the above iterative method and make it recursive; then write a program to test your answer.
• Check values from 1 to 40000.
• Do not use a helper method.
Sample Runs:
Enter a positive integer: 4726
The digital root of 4726 is: 1
Enter a positive integer: 39
The digital root of 39 is: 3
Notes/Hints/Tips:
• The program must be recursive for full credit.
• Get the non-recursive program to work first- then translate to recursion.
- This tutorial hasn't been purchased yet.
- Posted on Dec. 04, 2012 at 10:32:37AM

- This tutorial hasn't been purchased yet.
- Posted on Dec 04, 2012 at 6:35:16PM
- This tutorial was purchased 1 time and rated A+ by students like you.
- Posted on Dec 04, 2012 at 7:14:13PM