GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes charAt and loop question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "charAt and loop question" Watch "charAt and loop question" New topic
Author

charAt and loop question

Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
Hi, this is not part of a homework assignment or anything like that even though it may look that way.
I'm trying to work myself through a day 4 exercise in the Learning Java in 21 days book and here's my question.
How can I print out every letter in my string one at a time and everytime the loop encounters an 'e' it places the e in brackets.
I can get the first part no problem. It is the brackets that I'm struggling with. The error message states: "char cannot be dereferenced."
My code is below. Many thanks.



Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
Try this:


fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11351
    
  16

you might also want to use an 'else'


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
Thank you.
Based on your suggestion, I modified my code to below and it works fine.
Thanks again.


Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: charAt and loop question