Sunday 30 November 2014

Count the Number of Vowels in Java String

import java.util.Scanner;





public class SB

{

public static void main(String[] args) {

{
String test=null;

int j=0;

   char index[]={'a','e','i','o','u'};

System.out.println("Enter the string");

test= new Scanner(System.in).nextLine();

for (int i = 0; i < test.length(); i++)
                         {

for (int k = 0; k <  index.length; k++)
{
char element=test.charAt(i);

if(element == index[k])
{
j++;

}
}
}
System.out.println("No of vowels are "+j);
}
}
}










No comments:

Post a Comment