-3

enter image description here

not all code paths return a value in the method Isnt

There is a problem with Isnt method. Please help me

fubo
  • 44,811
  • 17
  • 103
  • 137

3 Answers3

0

After the for loop, insert a new return statement to return a value if there is nothing to iterate through.

Mark Diedericks
  • 331
  • 1
  • 9
0

There are values for a (e.g. a=2) which will not hit your for loop, so no return statement will be hit in that case.

Also please post code instead of screenshots.

user3292642
  • 711
  • 2
  • 8
  • 32
0

Since you have defined the method with a return type 'bool'. The compiler tries to check if a boolean value is actually returned from that method through all possible flows, without being bound by any conditions. Logically this method would work for all possible values, but you need to make the compiler understand that.

There's no need to put that extra check if(a<2), just scribble a 'return false' outside the for loop and you're good. That's probably a better way of coding.

'See the compiler helps you with your coding standard after all ;) '

Sam
  • 1
  • 1
  • Wrong : if `a == 2`, the method ends without reaching a `return` statement. See, the first `if` will be `false` and `Math.sqrt(2) < 2` so the `for` loop would never be entered, then you can't reach a `return`. (Same goes for 3) – Rafalon Sep 18 '17 at 06:42