java program for counting vowels , consonants , digits and whitespaces …
Java program for counting vowels , consonants , digits and white spaces
//this program is for counting vowels , consonants , digits and whitespaces .... import java.awt.*; import java.awt.event.*; class EventTest implements ActionListener { Frame fr; Button b1; TextField tf1,tf2,tf3,tf4,tf5; EventTest( ) { fr = new Frame("myframe" ); fr.setLayout(null); b1= new Button ("Calc") ; tf1 = new TextField() ; tf2 = new TextField() ; tf3= new TextField() ; tf4 = new TextField () ; tf5 = new TextField () ; tf1.setBounds( 50,50,100,50) ; b1.setBounds( 50,120,50,50); tf2.setBounds( 50,190,100,50) ; tf3.setBounds( 50,260,100,50) ; tf4.setBounds( 50,330,100,50) ; tf5.setBounds( 50,400,100,50) ; fr.add( tf1) ; fr.add( tf2) ; fr.add( tf3) ; fr.add(tf4) ; fr.add(tf5) ; fr.add( b1) ; b1.addActionListener( this ); fr.setSize(600,700); fr.setVisible(true); } public void actionPerformed (ActionEvent e ) { if ( e.getSource() == b1 ) { String str1 = tf1.getText() ; char ch[] = str1.toCharArray() ; int j= ch.length; int dcount = 0 ;int dconsonant =0;int dvowel =0; int dspace = 0; for ( int i = 0 ; i<j; i++ ) { if ( ch[i] == '1'| ch[i]== '2' | ch[i]== '3'| ch[i]== '4'| ch[i]=='5'|ch[i]=='6'|ch[i]=='7'| ch[i]=='8'|ch[i]=='9'|ch[i]=='0') dcount++; else if ( ch[i] == ' ' ) dspace++ ; else { for (char c = 65 ; c<123 ;c++ ) { if (c>90&c<97) { continue ; } else if ( c==65|c==97|c==69|c==73|c==79|c==85|c==101|c==105|c== 111|c==117 & ch[i]==c) { if (ch[i]== c){ dvowel++ ; break; } } else { if (ch[i] == c) { dconsonant++; break; } } } } } tf2.setText (" " + dcount); tf3.setText( ""+dvowel ); tf4.setText( ""+dconsonant); tf5.setText(""+dspace); } } public static void main (String s[] ) { new EventTest(); } }