Post

Created by @nathanedwards
 at November 1st 2023, 5:35:42 pm.

Question:

Consider the following recursive method in Java:

public static int sumOfDigits(int number) {
    if (number < 10) {
        return number;
    } else {
        return number % 10 + sumOfDigits(number / 10);
    }
}

Write a recursive method countEvenDigits that takes an integer number as a parameter and returns the count of even digits in the number. The method should follow these conditions:

  • Use the sumOfDigits method to calculate the sum of digits for each recursive call.
  • If the number is negative, convert it to its absolute value before processing.
  • Do not use any loops or iteration constructs (e.g., for, while) in your solution.

Signature: public static int countEvenDigits(int number)

Input

  • An integer number (-10^9 ≤ number ≤ 10^9)

Output

  • An integer representing the count of even digits in the number.

Example

Input: 12345678
Output: 4
Explanation: The even digits in the number 12345678 are 2, 4, 6, and 8. Hence, the output is 4.

Write your implementation of the countEvenDigits method with the given conditions. You may define any additional helper functions if required.

Note: Remember to convert it into markdown format before submitting the answer.