We are convert capital letter to lower case and then traverse string with for loop. To find vowel we compare a character in a String using the charAt() method.
public class CheckVowel {
public static void main(String Args[]) {
String test = "welcome that";
vowelTest(test);
}
public static void vowelTest(String test) {
int i;
char m = 0;
String st = test.toLowerCase();
for (i = 0; i < st.length(); i++) {
if ((st.charAt(i) == 'a') || (st.charAt(i) == 'e') || (st.charAt(i) == 'i') || (st.charAt(i) == 'o')
|| (st.charAt(i) == 'u')) {
m = st.charAt(i);
System.out.println("index is " + i + ", character is " + m);
}
}
}
}
Output :-
index is 1, character is e
index is 4, character is o
index is 6, character is e
index is 10, character is a