Design and implement an application that reads a string from the user and then determines and prints how many of each vowel appear in the string. Have a separate counter for each vowel. Also, count and print the number of non-vowel characters.
Note: The characters in the string must be considered as case-insensitive. i.e., You must consider both upper and lowercase letters as same.
Example Output:
Enter a string:
hello
Number of each vowel in the string:
a: 0
e: 1
i: 0
o: 1
u: 0
other characters: 3
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. Let me know for any help with any other questions. Thank You! =========================================================================== import java.util.Scanner; public class VowelsFrequency { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a string:"); String text = scanner.nextLine(); int aCount = 0, eCount = 0, iCount = 0, oCount = 0, uCount = 0; int otherCount = 0; for (int i = 0; i < text.length(); i++) { char letter = text.charAt(i); switch (letter) { case 'a': case 'A': aCount += 1; break; case 'e': case 'E': eCount += 1; break; case 'i': case 'I': iCount += 1; break; case 'o': case 'O': oCount += 1; break; case 'u': case 'U': uCount += 1; break; default: otherCount++; } } System.out.println("a: " + aCount); System.out.println("e: " + eCount); System.out.println("i: " + iCount); System.out.println("o: " + oCount); System.out.println("u: " + uCount); System.out.println("other characters: " + otherCount); } }
================================================================
Get Answers For Free
Most questions answered within 1 hours.