Thursday, 9 April 2020

Write a program to input a set of 20 letters. Convert each letter into upper case. Find and display the number of vowels and number of consonants present in the set of given letters.

import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter any 20 letters");
int vc = 0, cc = 0;
for (int i = 0; i < 20; i++)
{
char ch = in.next().charAt(0);           
ch = Character.toUpperCase(ch);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
                        vc++;
else if (ch >= 'A' && ch <= 'Z')
                cc++;       
}
System.out.println("Number of Vowels = " + vc);
System.out.println("Number of Consonants = " + cc);   
}
}

No comments:

Post a Comment