← All resources

Write a Program to input a String and print the number of Alphabets, Vowels and Special Characters.

import java.util.*;
public class Con_Vow
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        String s;
        char ch;
        int a=0, v=0, i, l;
        System.out.println("Enter a string:");
        s = sc.nextLine();
        s = s.toUpperCase();
        l = s.length();
        for(i=0;i<l;i++)
        {
            ch = s.charAt(i);
            if(ch>='A'&&ch<='Z')
            a++;
            if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
            v++;
        }
        System.out.println("The number of Alphabets: "+a);
        System.out.println("The number of Vowels: "+v);
        System.out.println("The number of Consonants: "+(a-v));
    }
}