Wednesday, September 4, 2019

BlueJ Program On Sentence To Count Frequency Of All Type Characters


This is a BlueJ program to accept a sentence and show the frequency of uppercase, lowercase, special characters and digits

Sample Input: Jamshedpur Mango Dimna Road:810012
Sample Output: No of uppercase characters: 4
No of lowercase characters: 20
No of special characters: 4
No of digits: 6




import java.util.Scanner;
class Star
{
String str1;
int i,len,c1,c2,c3,c4;
char ch;
Scanner sc=new Scanner(System.in);
public void read()
{
   System.out.print("\nEnter the sentence: ");
   str1=sc.nextLine();
len=str1.length();
for(i=0;i< len;i++)
{
  ch=str1.charAt(i);
  if(Character.isUpperCase(ch))
  c1++;
  else if(Character.isLowerCase(ch))
  c2++;
  else if(Character.isDigit(ch))
  c3++;
  else
  c4++;
}
  System.out.println("\nNo of Uppercase Characters: " + c1);
  System.out.println("\nNo of Lowercase Characters: " + c2);
  System.out.println("\nNo of Special Characters: " + c4);
  System.out.println("\nNo of Digits: " + c3);
}
public static void main(String args[])
{
 Star ob=new Star();
 ob.read();
  }
}


Related Post: BlueJ Programs on String/Sentence

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner