reset password
Author Message
304374842
Posts: 56
Posted 19:09 May 05, 2016 |

I am working on number five with reading in the string and my problem is that it won't accept any string length. I used nextLine as opposed to next but it still isn't accepting anything. Any thoughts?

kknaur
Posts: 540
Posted 20:19 May 05, 2016 |

If you are using nextLine, it should read the string no matter how many characters there are.  You will have to be more specific with what exactly your issue is.

304374842
Posts: 56
Posted 14:09 May 06, 2016 |

I think it has to do with my loop.  I am trying to convert each letter to a char and then printing out the uppercase ones (for the first part of that problem). I then created a boolean with isuppercase and I am trying to print out the ones that are uppercase, but it keeps telling me string index out of range. I have isolated the problem to the first part of my loop but I can't figure out what I am doing wrong.

rcamach7
Posts: 31
Posted 15:57 May 06, 2016 |

One of the reason I've found that error was because my code was looking for an index of a negative number, which doesn't exist since the index of strings go from 0 to however big the string is. I'm not sure if that's your problem and it's hard to know without looking at your code. 

Just make sure you aren't looking for an index of a string that goes beyond or below how big the actual string is. That's why you use a counter in loops starting from 0 and going < the string length.

Last edited by rcamach7 at 18:53 May 06, 2016.
kknaur
Posts: 540
Posted 18:23 May 06, 2016 |

Also make sure that you are not going out of bounds.  Usually you want to go to < the length of the string because the indexes start from 0 and if you go <= the length it will go out of bounds.

304374842
Posts: 56
Posted 18:26 May 06, 2016 |

That is what it was. I am working on the last part finding the index of the vowels.  I am getting the printout correct at first but ultimately it is: 

Position of Vowels: 0 5 7 11 11 17 19 7 23 7 7

Any idea why that is happening?  I have it pulling out the vowels but I am not sure why the index goes off.

kknaur
Posts: 540
Posted 18:28 May 06, 2016 |

How are you accounting for the spaces?

304374842
Posts: 56
Posted 18:30 May 06, 2016 |

I used an if statement and said if it included a vowel to print the index 

kknaur
Posts: 540
Posted 18:34 May 06, 2016 |

Make sure the logic is correct, be sure you are not being thrown off by spaces, and don't forget uppercase vs lowercase.