Tuesday, February 11, 2014

Java Programs

/* Program in Java to calculate lower case , upper case, numeric and special characters */
import java.io.*;
import java.lang.*;
class big
{
    public static void main(String arg[])throws IOException
    {
        DataInputStream sd=new DataInputStream(System.in);
        System.out.println("Enter a string:");
        String s=sd.readLine();
        int l=s.length();
        int n1=0,n2=0,n3=0,n4=0;
        for(int i=0;i<l;i++)
        {
            char ch=s.charAt(i);
            if(ch>='A' && ch<='Z')
            {
                n1=n1+1;
            }
            else if(ch>='a' && ch<='z')
            {
                n2=n2+1;
            }
            else if(ch>='1' && ch<='9')
            {
                n3=n3+1;
            }
            else
                n4=n4+1;
        }
        System.out.println("Upper Case:  "+n1);
        System.out.println("Lower Case:  "+n2);
        System.out.println("Digits:       "+n3);
        System.out.println("Special characters:  "+n4);
    }
}

No comments :

Post a Comment