In JAVA Tutorial, Module 4 quiz, 3rd question. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita

In JAVA Tutorial, Module 4 quiz, 3rd question.

the question is to arrange the code to return the greater of the two. In that code there should be "else" part otherwise there will be two return if a>b.

4th Mar 2017, 12:14 PM
Ngangbam Indrason
Ngangbam Indrason - avatar
1 Respuesta
+ 3
no, there won't... if(a>b) { return a; } returns a, if it's greater than b. if that's the case, a is returned and the method will be left. no further execution in that method. if b is greater than a, a won't be returned, because the command won't be executed. leaving the method only to return b. no else statement needed here, because there's no other option.
4th Mar 2017, 12:22 PM
Mario L.
Mario L. - avatar