This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Try changing your For statement to:
for (int ltr=0; ltr < sentence.length(); ltr++)
Since the string has a zero-based index (positions are 0 through n-1), your For statement is trying to index one place past the end of the string.
"Hello" : 0=H, 1=e, 2=l, 3=l, 4=o and 5=(error)
but the length of the string is 5 so you have to stop indexing through it at 4.
Joined: Aug 27, 2011
Thanks a lot guys, i don't have that error message anymore, and i understand now
but when i enter " Its April" , it just take the lowercase vowel
do i have to write a statement using equalsIgnoreCase() ??
Then you need to either add more test cases for capitol vowels, OR lower-case the character you're testing so that the upper-case char's will be caught. I believe there's a function which will ensure the characters are lower case before you do the compare.
Remember, Java is case-sensitive.