Saturday, 31 August 2013

Need some help trying to understand this code

Need some help trying to understand this code

I have been asked to: write a function boolean succeeds(char a, char b,
String s) that takes a string s and returns true if every occurrence of
the character b is always succeeded by the character a, and false
otherwise.
I came across this:
while (!s.equals("")) {
char c = s.charAt(0); // record first char
s = s.substring(1); // cut off first char
// if "first char is 'b' and next is
// not 'a'", we can return false
if (c == b && (s.equals("") || s.charAt(0) != a))
return false;
}
return true;
I cant quite get my head around it though? What does the s.equals"" mean?

No comments:

Post a Comment