Saturday, 1 December 2012

to display the number of consonants in the string


import java.io.*;
class string36
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s,k="";
int i,l,c=0,j,c1=0;
    System.out.println("Enter the string : - ");
    s=br.readLine();
    s=s+" ";
    l=s.length();
System.out.println("The each extracted word from the upper string The number of consonants the upper string  : - ");
for(i=0;i<l;i++)
{
if(s.charAt(i)!=' ')
{
k=k+s.charAt(i);
}
else
{
for(j=0;j<k.length();j++)
{
if((k.charAt(j)=='B')||(k.charAt(j)=='b')||(k.charAt(j)=='C')||(k.charAt(j)=='c')||(k.charAt(j)=='D')||(k.charAt(j)=='d')||(k.charAt(j)=='F')||(k.charAt(j)=='f')||(k.charAt(j)=='G')||(k.charAt(j)=='g')||(k.charAt(j)=='H')||(k.charAt(j)=='h')||(k.charAt(j)=='J')||(k.charAt(j)=='j')||(k.charAt(j)=='K')||(k.charAt(j)=='k')||(k.charAt(j)=='L')||(k.charAt(j)=='l')||(k.charAt(j)=='M')||(k.charAt(j)=='m')||(k.charAt(j)=='N')||(k.charAt(j)=='n')||(k.charAt(j)=='P')||(k.charAt(j)=='p')||(k.charAt(j)=='Q')||(k.charAt(j)=='q')||(k.charAt(j)=='R')||(k.charAt(j)=='r')||(k.charAt(j)=='S')||(k.charAt(j)=='s')||(k.charAt(j)=='T')||(k.charAt(j)=='V')||(k.charAt(j)=='v')||(k.charAt(j)=='W')||(k.charAt(j)=='w')||(k.charAt(j)=='t')||(k.charAt(j)=='X')||(k.charAt(j)=='x')||(k.charAt(j)=='Y')||(k.charAt(j)=='y')||(k.charAt(j)=='Z')||(k.charAt(j)=='z'))
{
c1++;
    }
    }
System.out.println(k+"\t\t\t\t\t\t\t"+c1);
c1=0;
k="";
}
}
}
}

No comments:

Post a Comment