Results 1 to 9 of 9
Thread: Needing help with strings
- 02-11-2013, 03:10 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Needing help with strings
I need to make a code that runs through the numbers 1 - 40 and replaces all the multiples of 5 with "Fizz" and all of the multiples of 6 with "Bang" and the number 30 "FizzBang". The current code I have now is pretty long, as I have each multiple typed out as an if statement, and even when I do that the integer still prints along with the word, it does not get replaced. What I was thinking about doing was making all the variables into 3 different strings but I cant seem to get it down. Also, how would you go about replacing the values rather than having them printed out along with the word "Fizz", "Bang" or "FizzBang"? Any help would be greatly appreciated.
- 02-11-2013, 03:22 PM #2
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
Re: Needing help with strings
Hi RUReady18,
The answer depends on your current implementation, are you modifying an array or just printing the output straight to screen?
The array is the longer way of doing it but definately doesn't require an if statement for every possibility.
Can you strip this down a bit and post what you have to give us an idea of what you are currently doing.
Regards.
- 02-11-2013, 03:33 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Needing help with strings
Currently there's at least one other thread discussing exactly this same topic. A classmate perhaps?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-11-2013, 04:12 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Needing help with strings
Why the duplicate post?
Replacing outputs with system.out.println
ETA: It's the same poster.Please do not ask for code as refusal often offends.
- 02-11-2013, 05:30 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Needing help with strings
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-11-2013, 05:49 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Needing help with strings
Welcome to the internet.
Billions of pages of stuff and hardly an original thought amongst them.Please do not ask for code as refusal often offends.
- 02-11-2013, 06:57 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
- 02-11-2013, 08:00 PM #8
- 02-11-2013, 08:42 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Needing help with GroupLayout
By Janohjk in forum AWT / SwingReplies: 2Last Post: 06-18-2011, 10:41 AM -
Beginner needing help
By Krakatau7 in forum New To JavaReplies: 15Last Post: 01-07-2011, 05:45 PM -
Ambitious Noob Here - Needing Guidance
By DizzyEwok in forum New To JavaReplies: 14Last Post: 06-28-2009, 09:25 PM -
All posts needing mod approval first?
By xcallmejudasx in forum Suggestions & FeedbackReplies: 0Last Post: 05-26-2009, 04:35 PM -
Needing Help!!
By kingjut06 in forum JDBCReplies: 1Last Post: 07-07-2007, 11:38 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks