Monday, 25 April 2011

Read Vowels from string using Java

Hi!

 Here is the code for reading vowels from a string using Java.

package readvowels;
class VowelRead{
 String[] s1 = {"adeeel","aqeeel","saaira","tahiraaa","naailaaa"};
 String s2 = "",vowels ="aeiouAEIOU";
 int a=0,b=0;int[] c;
VowelRead(){
 c = new int[100];
 for(int i=0;i<s1.length;i++){
  s2 = s1[i];
  for(int j=0;j<s2.length();j++){
   for(int k=0;k<vowels.length();k++){
    if(s2.charAt(j)==vowels.charAt(k))
      a++;
    }
    for(int y=0;y<String.valueOf(c).trim().length();y++){
     if(c[y] == a){
       b = c[y];
       System.out.println("The number of vowels in the string are: "+b+" at index "+y+", "+i);
     }
    }
    c[i] =a; a=0;
   }
  }
 }
public class Main{
public static void main(String[] args){
  VowelRead vr = new VowelRead();
 }
}