0
2.2kviews
Write a java program to find out number of uppercase and lowercases characters, blank spaces and digits and special characters from string.

Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology

Marks: 10 M

Year: Dec 2013

1 Answer
0
48views
import java.io.*;
class OccurenceCount
{
    public static void main(String args[]) throws IOException
    {
    BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
        System.out.println("\nEnter the String:\n");
        String s=br.readLine();
        int count[]=new int[5]; //to store total count
        String val[]={"Uppercase letters:  ", "Lowercase letters:  ","Numbers:\t    ","Blank
Spaces:\t    ","Special Characters: "}; //just for printing

        for(int i=0;i<s.length();i++) //finding total count
        {
            char res=s.charAt(i);
            if(res>='A'&&res<='Z')count[0]++;//uppercase
            else if(res>='a'&&res<='z')count[1]++; //lowercase
                 else if(res>='0'&&res<='9') count[2]++;  //numbers
                      else if(res==' ')count[3]++; //blank spaces
                            else count[4]++;  //special characters
        }

        System.out.println("----------------------------------------------\n\nThe number of
occurrences is as follows: \n");
        for(int i=0;i<count.length;i++)
            System.out.println(val[i]+count[i]+"\n");
    }
}
Please log in to add an answer.