Tuesday, 15 February 2011

java - Missing return Statement of multiple IFs -


Where's the problem? If I use a variable then it works fine, but I'm missing something.

  Public boolean xyzThere (string str) {if (str.length ()> gt 2) {if (str starts ("xyz")} {back true; } Else {for (int i = 1; i & lt; str.length () - 2; i ++) {if (str.substring (i, i + 3) .equals ("xyz") & amp; amp ;! Substring (i - 1, i) .equals (".")) {Back true; } Other {return false; }}}} Other {return false; }}   

In this situation, a return statement is required because the inside of the loop The code can not be reached

  else {for (int i = 1; i & lt; str.length () - 2; i ++) {if (str.substring (i, i + 3) .equals ("Xyz") & amp;! Str.substring (i - 1, i) .equals (".")) {Back true; } Other {return false; }}}  

No comments:

Post a Comment