This is a program to input a sentence and print the words that start with a vowel.......There is no syntax error but on executing and typing the sentence and pressing enter,I get a error saying :
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at sentence.main(sentence.java:22)
----------------------------------------------------
----------------------------------------------------
import java.util.*;
public class sentence
{
public static void main()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a sentence");
String s=in.nextLine();
String c="";
String d="";
int l=s.length();
for(int i=0 ; i<=l ; i++)
{
char b=s.charAt(i);
if(b!=' ')
{
c=c+b;
}
else
{
c=d;
}
char e=d.charAt(0);
if(e=='A' || e=='E' || e=='I' || e=='O' || e=='U' || e=='a' || e=='e' || e=='i' || e=='o' || e=='u' )
{
System.out.println(d);
}
c="";
}
}
}