Write a static recursive method that returns the number of digits in the integer passed to it as an argument of type int. Allow for both positive and negative arguments. For example, ?120 has three digits. Do not count leading zeros. Embed the method in a program, and test it.

A technique similar to that in RecursionDemo2, Listing 11.4, can be used for this Project First change the number to positive if it is negative. The base case is when the number has just one digit, which returns 1 if the result of the truncated division of the number by 10 is zero. If non-zero, a recursive call is made to the method, but with the original number reduced by one digit, and (1 + the value returned by the recursive call) is returned. In this fashion, each recursive call will add 1, but not until the base case is executed. The base case returns a 1 and the stacked calls can now “unwind,” each call executing in turn and adding 1 to the total. The first call is the last to execute and, when it does, it returns the number of digits.


See the code in NumberOfDigitsDemo.java.

Computer Science & Information Technology

You might also like to view...

____________________ is the process of arranging a group of items into a defined order.

a) Searching b) Sorting c) Selecting d) Helping e) none of the above

Computer Science & Information Technology

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

1. It is the drawing of diagrams rather than in their modification that CASE tools excel over the use of templates. 2. Object-oriented techniques are used when systems must change rapidly in response to dynamic business environments. 3. The four values of the agile approach are communication, simplicity, feedback and courage. 4. Open source software is distributed for free and then users pay for updates to the software. 5. The open source software community is a monoculture, a single unified community.

Computer Science & Information Technology

________ Preview shows you what the result of applying an edit or format change before you commit to applying it

Fill in the blank(s) with correct word

Computer Science & Information Technology

FIGURE OFF 1-1 Figure OFF 1-1 above shows a shape selected in Word. The Drawing Tools tab that is selected is a ____ tab.

A. Mini B. contextual C. toggle D. SmartArt

Computer Science & Information Technology