Basically I am checking to see if the first x in a string is followed by another x.
When the index of the character array gets to the first x it should add 1 to 'count' and exit out of the while loop.
When I tried stepping into it, I see that despite 'firstX' being equal to 1 it goes back to the for loop and not the while loop. Then it even makes 'firstX' equal to 2.
String str = "axxbb";
char[] charArray = str.toCharArray();
int firstX = 0;
int secondX = 0;
while (firstX < 1) {
for (int i = 0; i < charArray.length - 1; i++) {
if (charArray[i] == 'x') {
firstX = firstX + 1;
// firstX becomes 1 here after detecting the first x in the string
secondX = i + 1;
}
}
}