Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code is intended to return only even numbers greater than 0 . If an even number greater than 0 is passed to the

The following code is intended to return only even numbers greater than 0. If an even number greater than 0 is passed to the method, it should return that number. If an odd number or zero is passed, it should return the next highest even number.
1: public int returnEven(int number)
2: {
3: if (number %2==0)
4: {
5: return number;
6: }
7: else if (number ==0)
8: {
9: return number +2;
10: }
11: else
12: {
13: return number +1;
14: }
15: }
Java
Does the code work as intended?
Yes.
Incorrect Answer
No, the mod function on line 3 should read number %2==1 to find even numbers.
No, the else if on line 7 and the else on line 11 should just be if statements.
Correct Answer
No. Zero will get returned on line 5 and not make it to line 7.

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions