Question
Question 3 Item 3 Consider the following method, which is intended to return the sum of all the even digits in its parameter num. For
Question 3
Item 3
Consider the following method, which is intended to return the sum of all the even digits in its parameter num. For example, sumEvens(15555234) should return 6, the sum of 2 and 4.
/** Precondition: num >= 0 */
public static int sumEvens(int num)
{
if (num < 10 && num % 2 == 0)
{
return num;
}
else if (num < 10)
{
return 0;
}
else if (num >= 10 && num % 2 == 0)
{
/* missing statement */
}
else
{
return sumEvens(num / 10);
}
}
Which of the following can be used as a replacement for /* missing statement */ so that the sumEvens method works as intended?
A. return sumEvens(num % 10);
B. return sumEvens(num / 10);
C. return num % 10 + sumEvens(num % 10);
D. return num % 10 + sumEvens(num / 10);
E. return num / 10 + sumEvens(num % 10);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started