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:
Signature: public static int countEvenDigits(int number)
Input
Output
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.