Sunday, January 1, 2012

Find total no on capital, small letter and also digit in a given string in Java

Example



import java.io.*;
public class A12
{
public static void main(String args[])
throws IOException
{


String s="";
String s1="";
char ch=65;
int a,b=0,c=0,d=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine();
a=s.length();
for(int i=0;i<a;i++)
{
ch=s.charAt(i);
if (ch>=97 && ch<=122)
{
b=b+1;

}
else if(ch >=65 && ch<=91)
{
c=c+1;
}
else
{
d=d+1;
}
}
System.out.println(a);
System.out.println(s1);
System.out.println("Total Small character:"+b);
System.out.println("Total Capital character:"+c);
System.out.println("Total digits:"+d);
}
}

No comments:

Post a Comment