WAP to take a sentence as input, now count vowels in sentence

import java.util.*; class T15 { public static void main(String[] args) { String str; int c = 0; Scanner sc = new Scanner(System.in); System.out.println("Enter a sentence : "); str = sc.nextLine(); for (int i = 0; i < str.length(); i++) { String str1 = str.toLowerCase(); char ch = str1.charAt(i); if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { c++; } } System.out.println("Number of vowels in the sentence : " + c); } } Copy Code
Expected Output:
Input:
Enter a sentence : Hardik Srivastava

Output:
Number of vowels in the sentence : 6