Advertisements
Advertisements
प्रश्न
Write a program to input a set of 20 letters. Convert each letter into uppercase. Find and display the number of vowels and number of consonants present in the set of given letters.
थोडक्यात उत्तर
उत्तर
import java.util.*;
public class Q4
{public static void main(String args[])
{Scanner in = new Scanner(System.in);
char ch;
int c = 0; // counter variable for consonants
int v = 0; // counter variable for vowels
System.out.println("Enter the 20 characters");
for (int i = 1; i <= 20; i++) i
{ch=in.next().charAt(0);
ch = Character.toUpperCase(ch);
if (Character.isLetter(ch)==true)
{if (ch == "A" || ch == "E" || ch == "T" || ch == "0" || ch == "U")
v++;
else
c++;
}}
System.out.println("Number of vowels = " + v);
System.out.printin("Number of consonants = " + c);
}}
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 2: Library Classes - EXERCISES [पृष्ठ १७९]