This program should check the string you input for vowels and then output the amount of vowels. However, when I run the program, the counter displays 0. There are no errors being displayed by Eclipse.
I would expect that if I type in hello
then it would display 2
, but it always displays 0
.
import javax.swing.*;
public class Lab5 {
public static boolean isVowel(char x) {
if (x == 'A' || x == 'E' || x == 'I' || x == 'O' || x == 'U') {
return true;
}
else {
return false;
}
}
public static void main(String[] args) {
String seq;
boolean vowel;
int counter = 0;
seq = JOptionPane.showInputDialog(null, "Please enter a sequence of characters: ");
seq.toUpperCase();
for (int i=0; i<seq.length(); i++) {
vowel = isVowel(seq.charAt(i));
if (vowel == true) {
counter++;
}
}
JOptionPane.showMessageDialog(null, "The number of vowels in your sequence of characters is : " + counter);
}
}