java - returning true with an occurance of a letter in a string? -


It should be corrected because string is 'c' in S but is it returning incorrectly?

  public class A {public static zero main (string [] args) {System.out.println (in ('c', "cccc")); } Public static boolean includes (four c, string s) {boolean to_return = true; While (true) {if (s.equals ("")} {return_return = false; } Else {char c2 = s.charAt (0); If (c == c2) {to_return = true; }} S = s.sstring (1); }}}  

I do not know why is not it? It only gives false if the string is empty which is clearly (not allowed to use for loop etc.).

You are not returning to true anywhere in your code, therefore s.equals (" ") is evaluated true < / Code> and false .

  if (c == c2) {to_return = true;}  

to

  if (c == c2) {back true;}  

Comments