Home / Blue J / Program to count the number of alphabets, digits, spaces, special symbols

Program to count the number of alphabets, digits, spaces, special symbols

This is a program to count the total number of letters, digits, blank spaces and special symbols in a given string.

import java.io.*;
class count
{
void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
System.out.println("enter the String");
String s=br.readLine();
int i,l,c1=0,c2=0,c3=0,sp=0;
char ch;
l=s.length();
for(i=0;i<l;i++)
{
ch=s.charAt(i);
if(Character.isLetter(ch))
++c1;
else if(Character.isDigit(ch))
++c2;
else if(ch==' ')
++sp;
else
++c3;
}
System.out.println("no of Letter="+c1);
System.out.println("no of Digit="+c2);
System.out.println("no of Spaces="+sp);
System.out.println("no of Symbol="+c3);
}
}

 OUTPUT:

count-the-alphabets-numbers-and-special-symbols

Also See:   java program for pattern#6

Check Also

Java program to implement polymorphism

Java program to implement polymorphism: Polymorphism is a technique in java with which you can ...

2 comments

  1. thanxxxxxx you helped a lot in my project!!!!

  2. Can you give code for string manipulation
    Q1- in a sentence of words , the 1 st character and last character of each word must be swapped.
    Eg- input- java is awesome.
    Output – aavj si ewesoma.
    Q2. In a string , calculate the repeated characters and print repeated character in descending order.
    Eg- input- Mississippi.
    Output – s-4
    i-4
    P-2
    M-1.
    Help me out soon guys ..

Leave a Reply

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