You are here:   HomeJava ProgrammingStreamCounting Uppercase, LowerCase, Digits in a File Java Example
by Dinesh Thakur Category: Stream

 

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





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article