134k views
8 votes
Complete the program below named CountVowels so that it reads in a string, counts all the vowels in that string, and prints out the number of vowels in the string.

For example, given the input string of "Hello, World!", the program should print out the value 3 for the three vowels, "eoo", in that string.
Complete the following file:
CountVowels.java
import java.util.Scanner;
/**
Reads a string and counts all vowels contained in that string.
Vowels are A E I O U a e i o u.
Input: the value of s, a string
Output: the number of all the vowels in s
*/
public class CountVowels
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String s = in.nextLine();
// your work here
System.out.println(count);
}
}

User Tim Givois
by
7.9k points

1 Answer

11 votes

Answer:

Answered below

Step-by-step explanation:

public class CountVowels{

public static void main (String[] args){

Scanner in = new Scanner(System.in);

String words = in.nextline();

String vowels = "aeiouAEIOU";

int count = 0;

for( int i =0; I< words.length-1; I++){

for( int j = 0; j < vowels.length - 1; j++){

if(words [I] == vowels[j]){

count++;

}

}

}

System.out.print(count);

}

}

User Leszek Zarna
by
7.5k points