0

I have a for loop that for the life of me I cant figure out why it isnt incrementing properly. I know that it is due to the 'If Statement' that is nested in the first For Loop but I have no idea how to fix it. Any help would be greatly apreciated.

public static boolean ifMatches(String word){
    String[] split = word.split("z");
    for(int i = 0; i<split.length; i++){
        if(vowelCount(split[i]) == 2){
            return true;
        }else{
            return false;
        }       
    }
    return false;
}


public static int vowelCount(String part){
  int vowelCounter = 0;
    for( int i = 0; i <part.length(); i++){
       if(isVowel(part.charAt(i)))
        vowelCounter++;
    }
    return vowelCounter;
6
  • 3
    If is not a loop Commented Apr 9, 2017 at 8:00
  • Granted, it is a conditional statement Commented Apr 9, 2017 at 8:01
  • Given the input of 'ozoozoo' isnt the arrary size [2]? [0]=o [1]=oo [2]=ooo Commented Apr 9, 2017 at 8:11
  • Question is unclear without seeing your word input Commented Apr 9, 2017 at 8:11
  • Yep it is only running once Commented Apr 9, 2017 at 8:11

1 Answer 1

3

The loop is not incrementing because you return a value in the if statement and the else statement; there is no way for the for loop to go through more than one iteration because it always returns a value on the first iteration.

To fix your problem, remove the else {} block.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.