// **************************************************************** // CountVowe
ID: 3629710 • Letter: #
Question
// ****************************************************************// CountVowels.java
//
// Determines and prints how many of each vowel appear in the entire string.
// ****************************************************************
import java.util.Scanner;
public class CountVowels
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a string");
String line = scan.next();
//convert all characters to lower cases
line = line.toLowerCase();
//counter is used to count the number of vowels
int counter = 0;
//Step1: Complete the following for loop so that
//the index “i” goes from the beginning of the string to the end
//Hint: use length( ) method
for (int i = 0; ; )
{
//Step2: Complete the following if statement to check if
//character is one of vowels ‘a’,’e’,’i’,’o’, or ‘u’
//Hint: use charAt( ) method
if (line.charAt(i) == 'a' …………………..)
{
counter++;
}
}
System.out.println("The string " + line + " contains " + counter + " vowel(s)");
}
}
Explanation / Answer
public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a string"); String line = scan.next(); //convert all characters to lower cases line = line.toLowerCase(); //counter is used to count the number of vowels int counter = 0; //Step1: Complete the following for loop so that //the index “i” goes from the beginning of the string to the end //Hint: use length( ) method for (int i = 0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.