Given a string, return true if the first instance of "x" in the string is immediately followed by another "x"
You have two problems :
You break after the first iteration of the loop.
Even after you remove that break, you will return true if the first x is not followed by an x, but another x does (for example -
axaxxa
will wrongly return true).
A better implementation :
boolean doubleX(String str) {
for(int i=0;i<str.length()-1;i++){
if(str.charAt(i)=='x')
if (str.charAt(i+1)=='x') {
return true;
} else {
return false;
}
}
return false;
}