Question: CountVowels specs ** CountVowels Ask the user to enter a string. Print how many different vowels there are in the string (e.g. aaaee has


CountVowels specs ** CountVowels Ask the user to enter a string. Print how many different vowels there are in the string (e.g. "aaaee" has 2 different vowels). Ignore case, i.e. 'A' and 'a' are considered to be the same vowel. y' is not considered a vowel. Look at the examples of output below and match them. Make sure you do match the examples below. Example: When the user enters the string: "It's Owl Stretching Time" the program should say that there are 3 different vowels in the string. DO NOT USE LOOPS. Hint You could solve this problem by using a method of String called indexOf indexOf(ch): Returns the index within this string of the first occurrence of the character ch. If ch is not in the string, it returns -1 For example: String foo; foo = "hello"; System.out.println(foo.indexOf('')); prints 2 System.out.println(foo.indexOf('x')); prints -1 Examples % java Count Vowels % java CountVowels enter a string: qqqqqq the string contains no vowels % java Count Vowels enter a string: qqqaaaaaqqaaaaaqq the string contains: 1 vowel % java Count Vowels enter a string: qqqqqqqqqqqqqqqu the string contains: 3 vowels % java CountVowels enter a string: pppppapppp the string contains: 1 vowel % java Count Vowels enter a string: aaeeiioouu the string contains: 5 vowels % Previous Next 123456780 20E CountVowels.java public class CountVowels { public static void main(String arg []) throws Exception { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); Scanner s=new Scanner(System.in); System.out.print("Enter the string: "); String input-br.readLine(); int c=0; if(input.indexOf('A')>-1 || input.indexOf('a')>1) { } 9 10 11 { 12 13 } 14 15 16 17 18 19 { 20 21 } 22 23 { 24 25 } 26 27 { 28 29 30 31 C++; if(input.indexOf('E')>-1 || input.indexOf('e')>-1) C++; if(input.indexOf('I')>-1 || input.indexOf('i')>-1) C++; if(input.indexOf('0')>-1 || input.indexOf('0')>-1) C++; if(input.indexOf('U')>-1 || input.indexOf('u')>-1) C++; System.out.println("the string contains:"+ C +"vowels"); 32 33 } 21
Step by Step Solution
There are 3 Steps involved in it
Heres the corrected code Java public class CountVowels public static void mainString arg throws Exce... View full answer
Get step-by-step solutions from verified subject matter experts
