5
Define a class to accept a string and convert it into uppercase. Count and display the number of vowels in it.
Input: robotics
Output: ROBOTICS
Number of vowels: 3
Show SolutionHide Solution↓
import java.util.Scanner;
public class KboatCountVowels
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the string: ");
String str = in.nextLine();
str = str.toUpperCase();
str += " ";
int count = 0;
int len = str.length();
for (int i = 0; i < len - 1; i++)
{
char ch = str.charAt(i);
if(ch == 'A'
|| ch == 'E'
|| ch == 'I'
|| ch == 'O'
|| ch == 'U')
count++;
}
System.out.println("String : " + str);
System.out.println("Number of vowels : " + count);
}
}
