Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text


Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text                                   
  Week – 3
c) Aim: To Write a Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text.
 
Description :
The input for this program is a line of text and the output how many vowels, consonants, digits and special characters that given lines contain. Firstly, read a line of text from the user and store that line as a string of name ‘n’. Now read each and every character of the string n usint the method charAt() pre-defined in String class. Check each  and every character,ch, whether it is a vowel or consonant. If the ch is one from ‘a,e,i,o,u,A,E,I,O,U’ then it is a vowel otherwise it is an consonant. If ch is not an vowel or consonant, it may be a digit or special character or space. If ch is any number between 0-9,then it is a digit. Ch may be a space. If ch is not any one of these  cases, then definitely it is a special character or special symbol.
 
Source code :
import  java.io.*;
import java.util.*;
public class Count
{
            public static void main(String ar[])
            {
                        int v=0,c=0,d=0,sm=0,sp=0,w=0;
                        System.out.println(“Enter text : “);
                        Scanner s=new Scanner(System.in);
                        String n=s.nextLine();
                        for(int i=0;i<n.length();i++)
                        {
                                    char ch=n.charAt(i);
                                    if(ch==’0’||ch==’1’||ch==’2’||ch==’3’||ch==’4’||ch==’5’||ch==’6’||ch==’7’||ch==’8’||ch==’9′)    
d++;
else if(ch==’a’||ch==’e’||ch==’i’||ch==’o’||ch==’u’||ch==’A’||ch==’E’||ch==’I’||ch==’O’||ch==’U’)
         v++;
                                    else if(ch>=65 && ch<=123)
                                                c++;
                                    else if(ch==’ ‘)
                                    {
                                                sp++;
                                                w++;
                                    }
                                    else sm++;
           
                        }
                        System.out.println(“Vowels :  “+v);
                        System.out.println(“Consonants :  “+c);
                        System.out.println(“Digits :  “+d);
                        System.out.println(“Spaces :  “+sp);
                        System.out.println(“Symbols :  “+sm);
                        System.out.println(“Words :  “+w);
            }
}
Sample output :
Enter Text :
HI! we are from MITS established in 1998.
Vowels :11
Consonants :17
Digits :4
Spaces :7
Symbols :2
Words :7
Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text wikipedia

Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text

https://www.geeksforgeeks.org/program-count-vowels-consonant-digits-special-characters-string/

Have any Question or Comment?

4 comments on “Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text

[…] program that reads a file and displays the file on the screen with a line number before each line Java program to make frequency count of vowels, consonants, special symbols, digits, words in a give… Java program for sorting a given list of names in ascending order Write a java program to perform […]

[…] Java program to make frequency count of vowels, consonants, special symbols, digits, words in a give… […]

[…] Java program to make frequency count of vowels, consonants, special symbols, digits, words in a give… […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories