0

Im trying to add a counter every time a string has a vowel in it with a for loop that only runs with alloted test cases but im getting the wrong output.

public class Prob03 {
    public static void main(String[] args) {
        int count = 0;
        Scanner scan = new Scanner(System.in);
        int runs = scan.nextInt();
        
        for (int l = 0; l < runs; l++) {
            String sentence = scan.nextLine().toLowerCase();
            sentence = "\n" + sentence;
            for (int i = 0; i < sentence.length(); i++) {
                char vowels = sentence.charAt(i);
                if (vowels == 'a' || vowels == 'e' || vowels == 'i' || vowels == 'o' || vowels == 'u') {
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}
ib.
  • 27,830
  • 11
  • 80
  • 100

0 Answers0