-1

/ * Finds the first vowel in a word and returns its location * */


public static int findFirstVowel (String word) {
    int consonant = 0;
    for(int count = 0; count < word.length(); count++){
        word.toUpperCase();
   char letter1 = word.charAt(count);
   String letter2 = (Character.toString(letter1));
   if (isVowel(letter2) == true){
    //consonant = 0;
    return (count);
     }
    }
    return (-1);
}**
htshame
  • 6,599
  • 5
  • 36
  • 56
  • `if (isVowel(letter2) == true){` -> `if (isVowel(letter2)){`. There's no need to compare booleans like this. – Ben R. Mar 21 '19 at 17:51

1 Answers1

0

Your problem is with word.toUpperCase(). Since Strings are immutable in Java, this creates a new a uppercase String, which you aren't using. The correct way to do what you are trying to do is:

public static int findFirstVowel (String word) {
    int consonant = 0;
    word = word.toUpperCase(); // you need to set word back to the uppercase version

    for (int count = 0; count < word.length(); count++) {
        char letter1 = word.charAt(count);
        String letter2 = (Character.toString(letter1));

        if (isVowel(letter2)) {
            return count;
        }
    }

    return -1;
}
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80