Write a recursive method that will compute the sum of the digits in a positive number.

What will be an ideal response?


```
public static long sumDigits(long number){
long result;
if(number == 0)
// base case
result = 0;
else {
long digit = number % 10;
if(digit < 0)
digit = -1 * digit;
result = digit + sumDigits(number/10);
}

return result;
}
```

This code is in Methods.java.

Computer Science & Information Technology

You might also like to view...

Answer the following statements true (T) or false (F)

1. The default copy constructor and default operator = provide deep copy. 2. In deep copy, pointers are followed and data and the pointer structure are duplicated. 3. A function can return an array. 4.An array name is a constant pointer to array base type.

Computer Science & Information Technology

To delete a label from a form, click the label, then press the ____ key on the keyboard.

A. Cut B. Delete C. Remove D. Purge

Computer Science & Information Technology

A ____ is a database object that extracts data from one or more tables in a database according to criteria that you set.

A. table B. query C. filter D. mirror

Computer Science & Information Technology

A(n) ______ TV is an Internet-capable, high-definition television on which you can use the Internet to watch video, listen to the radio, play games, and communicate with others.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology