Advertisement
sujonshekh

counting vowels and consonants in java

Jun 4th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. /**
  5.  *Java Program to count vowels and consonants in a String or name.
  6.  * @author Sharif
  7.  */
  8. public class counter {
  9.     public static void main(String[] args) {
  10.         // TODO code application logic here
  11.         Scanner sc;
  12.         sc= new Scanner(System.in);
  13.         System.out.println("Give any sentence or name");
  14.         String str=sc.nextLine();
  15.       char [] name = str.toCharArray();
  16.       int v=0,c=0;
  17.       for(int i=0; i<name.length; i++)
  18.       {
  19.           if(name[i]==' ')
  20.               continue;
  21.           if(name[i]=='a'||name[i]=='e'||name[i]=='i'||name[i]=='o'||name[i]=='u'
  22.             ||name[i]=='A'||name[i]=='E'||name[i]=='I'||name[i]=='O'||name[i]=='U')
  23.               v++;
  24.           else
  25.               c++;
  26.       }
  27.       System.out.println("number of vowel is "+v);
  28.       System.out.println("number of consonent is "+c);
  29.     }
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement