Advertisement
Shailrshah

Counting the number of vowels in a string

Dec 18th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2. class CountingVowels{
  3.         public static void main(String args[]){
  4.                 Scanner sc = new Scanner(System.in);
  5.                 System.out.print("Enter a string: ");
  6.                 String string = sc.nextLine();
  7.                 string = string.toLowerCase();
  8.                 int counter = 0;
  9.                 for(int i = 0; i < string.length(); i++)
  10.                         if(string.charAt(i) == 'a' || string.charAt(i) == 'e' || string.charAt(i) == 'i' || string.charAt(i) == 'o' || string.charAt(i) == 'u')
  11.                                 counter++;                                
  12.                 System.out.println("The number of vowerls are "+counter);
  13.         }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement