In: Computer Science
programing language JAVA:
Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
import java.util.*; public class VowelCountString { public static int countVowels(String s) { int count = 0; for(int num = 0;num<s.length();num++){ if (s.charAt(num)=='a'||s.charAt(num)=='A'|| s.charAt(num)=='e'||s.charAt(num)=='E'|| s.charAt(num)=='i'||s.charAt(num)=='I'|| s.charAt(num)=='o'||s.charAt(num)=='O'|| s.charAt(num)=='u'||s.charAt(num)=='U') count++; } return count; } public static void main(String[]args) { String str; Scanner sc= new Scanner(System.in); System.out.print("Input the string: "); str=sc.nextLine(); System.out.println("Number of vowels in the string: "+countVowels(str));} }