+ 1

Can anyone please tell me What is the mistake in My code,there iz a problem with return statement.

i created a static function named sevenBoom which takes int array as an argument and returns "boom" if there is number 7 in array otherwise it returns "no 7 in array" . Link to my code https://code.sololearn.com/c7H6dV0ZyCGl/?ref=app

16th May 2020, 1:56 PM
Prabhjot Singh
Prabhjot Singh - avatar
7 ответов
+ 3
Prabhjot Singh You need to write return statement outside loop. Also use return statement in loop when condition will satisfy otherwise program will stop there and next iteration will not work and you will never get actual result. public static String sevenBoom(int[] numarr){ for(int i:numarr){ if (i == 7) { return "no 7 in array"; } } return "Boom!"; } Edited - I just provided solution here. Don't compare with original code.
16th May 2020, 2:01 PM
A͢J
A͢J - avatar
+ 2
Martin Taylor To give solutions I don't think we need to write same code as given in problem. Anyway we don't need to discuss on this.
16th May 2020, 7:38 PM
A͢J
A͢J - avatar
+ 1
Martin Taylor I know. I just gave solution. Don't think that is Wrong. I intensely changed value.
16th May 2020, 5:49 PM
A͢J
A͢J - avatar
+ 1
Martin Taylor Now I have changed. Now it will return "no 7 in array"? I thought people have sense here.
16th May 2020, 5:52 PM
A͢J
A͢J - avatar