In this we learn Program to count letter, Digit, Special Char, Blank Space in a sentence
Program to count letter, Digit, Special Char, Blank Space and Words in the sentence
import java.io.*;
class Space{
public static void main(String args[]) throws IOException
{
String s; //Declaration os String varible to read the sentence
BufferedReader r=new BufferedReader(new
InputStreamReader(System.in));//assigning new input method
System.out.println("Enter the sentence"); //prompt the user to
enter the sentence
s=r.readLine(); //Read the user entered sentence into variable
int i=1; //for count of loop
int a=0; //For count of alphabet
int d=0; //For count of digit
int sc=0; //For count of special character
int bs=0; //For count of blank spaces
int w=1; //For count of words
char ch; //For a single character of sentence
int l=s.length(); //String length of sentence in variable l
for(i=0;i<l;i++)
{
ch=s.charAt(i);
if(Character.isLetter(ch) )
++a;
else
if(Character.isDigit(ch))
++d;
else
if(ch==' ')
++bs;
else
++sc;
}
System.out.println("There are "+a+" Alphabet");
System.out.println("There are "+d+" Digit");
System.out.println("There are "+sc+" Special Character");
System.out.println("There are "+bs+" Blank Spaces");
for(i=0;i<l;i++)
{
if(s.charAt(i)==' ')
w++;
}
System.out.println("There are "+w+" Word");
}//END OF MAIN
}//END OF CLASS
OUTPUT.
C:\A>javac Space.java
C:\A>java Space
Enter the sentence
January2018 #$ ,
There are 7 Alphabet
There are 4 Digit
There are 3 Special Character
There are 2 Blank Spaces
There are 3 Word
Also, you can use the Java compiler to compile a program.
Also, View: – Write a program to create a registration form using AWT.
I think this is the best post till now
Thanks a lot
Your method of explaining the whole thing in this post is, in fact, pleasant, every one be capable of effortlessly be aware of it, Thanks a lot.