KnowledgeBoat Logo

Computer Applications

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.

Java

Java Library Classes

106 Likes

Answer

import java.util.Scanner;

public class Kboat20LetterSet
{
    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);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of 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.

Answered By

48 Likes


Related Questions