Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- *Java Program to count vowels and consonants in a String or name.
- * @author Sharif
- */
- public class counter {
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner sc;
- sc= new Scanner(System.in);
- System.out.println("Give any sentence or name");
- String str=sc.nextLine();
- char [] name = str.toCharArray();
- int v=0,c=0;
- for(int i=0; i<name.length; i++)
- {
- if(name[i]==' ')
- continue;
- if(name[i]=='a'||name[i]=='e'||name[i]=='i'||name[i]=='o'||name[i]=='u'
- ||name[i]=='A'||name[i]=='E'||name[i]=='I'||name[i]=='O'||name[i]=='U')
- v++;
- else
- c++;
- }
- System.out.println("number of vowel is "+v);
- System.out.println("number of consonent is "+c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement