by Dinesh Thakur

 

import java.io.*;

class CountingUppercaseJavaExample
{
         public static void main(String args[]) throws IOException
        {
               String t;
               int up,lo,nu,sp,n,i,m;
               BufferedReader fin = new BufferedReader(new FileReader(args[0]));
               up=lo=nu=sp=0;
               while(true)
                      {
                        try
                            {
                                 t=fin.readLine();
                                 if (t==null) break;
                                 n = t.length();
                                 for (i=0;i<=n-1;i++)
                                      {
                                         m= t.charAt(i);
                                         if(m>=97 && m<=122)
                                               {
                                                  lo++;
                                                }
                                                  else
                                                       {
                                                            if(m>=65 && m<=90)
                                                               {
                                                                   up++;
                                                                }
                                                                      else
                                                                            {
                                                                                 if(m>=48 && m<=57)
                                                                                     {
                                                                                         nu++;
                                                                                     }
                                                                                         else
                                                                                            {
                                                                                                sp++;
                                                                                             }
                                                                             }
                                                       }
                                         }
                             }
                           catch(IOException e){}
                     }
                      System.out.println("the number of lower case characters are"+lo);
                      System.out.println("the number of upper case characters are"+up);
                      System.out.println("the number of numerical digits are"+nu);
                      System.out.println("the number of other characters are"+sp);
         }
 }

Counting Uppercase, LowerCase, Digits in a File Java Example