Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class CountVowels
- {
- public static void main(String args[])
- {
- Scanner sc=new Scanner(System.in);
- System.out.println("Enter a string");
- String input=sc.nextLine();
- System.out.println("Number of vowels = "+count(input));
- }
- static int count(String s)
- {
- int cnt=0,i;
- for(i=0;i<s.length();i++)
- {
- if(isVowel(s.charAt(i)))
- cnt++;
- }
- return cnt;
- }
- //here is the isVowel method
- static boolean isVowel(char ch)
- {
- if(ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U')
- return true;
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment