Write a java program to count the number of vowels in the string. Write a program to read a string and count the number of vowels present in it.
Include a class UserMainCode with a static method tellVowelCount which accepts the string. The return type is the integer giving out the count of vowels.
Note: The check is case-insensitive.
Input and Output Format:
Input consists of a string.
Output consists of integer.
Refer sample output for formatting specifications.
Sample Input 1:
NewYork
Sample Output 1:
2
Sample Input 2:
Elephant
Sample Output 2:
3
java program to count the number of vowels in the string
package com.demo;
import java.util.*;
public class Main {
public static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
String s = sc.nextLine();
int max = 0;
int count = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O'
|| c == 'U') {
count++;
}
}
if (count > max) {
max = count;
}
System.out.print(max);
}
}