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

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!