This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

charAt and loop question

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


 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might also want to use an 'else'
 
Charles Angemeyer
Greenhorn
Posts: 22
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic