Question: Java - Recursion Write a recursive method largestDigit that accepts an integer parameter and returns the largest digit value that appears in that integer. Your

Java - Recursion

Write a recursive method largestDigit that accepts an integer parameter and returns the largest digit value that appears in that integer. Your method should work for both positive and negative numbers. If a number contains only a single digit, that digit's value is by definition the largest. The following table shows several example calls:

Call

Value Returned

largestDigit(14263203)

6

largestDigit(845)

8

largestDigit(52649)

9

largestDigit(3)

3

largestDigit(0)

0

largestDigit(-573026)

7

largestDigit(-2)

2

Obey the following restrictions in your solution:

  • You may not use a String, Scanner, array, or any data structure (list, stack, map, etc.).
  • Your method must be recursive and not use any loops (for, while, etc.).
  • Your solution should run in no worse than O(N) time, where N is the number of digits in the number.

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!