• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

charAt and loop question

 
Charles Angemeyer
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:


 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might also want to use an 'else'
 
Charles Angemeyer
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
Based on your suggestion, I modified my code to below and it works fine.
Thanks again.


 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic