Question: Write a program that reads a word and prints the number of vowels in the word. For this exercise, assume that a e i o
Write a program that reads a word and prints the number of vowels in the word. For this exercise, assume that a e i o u y are vowels. For example, if the user provides the input "Harry", the program prints 2 vowels.
import java.util.Scanner;
/** * * @author oneken */ public class HW2Q3 {
/** * @param args the command line arguments */ public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enster a word: "); String strLine = in.next(); int count = 0; for (int x = 0; x < str.length(); x++) { char ch = str.charAt(x); //check for characters a,e,i,o,u,y if ((ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y')); { count++; } } System.out.println("Number of vowels: " +count); } } keep getting error - not sure what I am doing wrong.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
