Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

b. Have you been precise about when you desire the feedback?

Answered: 1 week ago