Results 1 to 9 of 9
  1. #1
    RUReady18 is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default 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.

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default 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.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,508
    Blog Entries
    7
    Rep Power
    20

    Default Re: Needing help with strings

    Currently there's at least one other thread discussing exactly this same topic. A classmate perhaps?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,997
    Rep Power
    19

    Default 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.

    ** This space for rent **

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,508
    Blog Entries
    7
    Rep Power
    20

    Default Re: Needing help with strings

    Quote Originally Posted by Tolls View Post
    ETA: It's the same poster.
    Hrmph, so I see now; I remember still another thread where exactly the same mistake was made; sometimes I wonder where progression comes from if everybody makes the same mistakes over and over again ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,997
    Rep Power
    19

    Default 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.

    ** This space for rent **

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,508
    Blog Entries
    7
    Rep Power
    20

    Default Re: Needing help with strings

    Quote Originally Posted by Tolls View Post
    Welcome to the internet.
    Billions of pages of stuff and hardly an original thought amongst them.
    Duh, I made a copy of the internet for a bedtime read but knowing this now, I'm going to do something else ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,229
    Rep Power
    19

    Default Re: Needing help with strings

    Needing help with strings-sshot4f563c627c06b.gif
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,508
    Blog Entries
    7
    Rep Power
    20

    Default Re: Needing help with strings

    :-D

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Needing help with GroupLayout
    By Janohjk in forum AWT / Swing
    Replies: 2
    Last Post: 06-18-2011, 10:41 AM
  2. Beginner needing help
    By Krakatau7 in forum New To Java
    Replies: 15
    Last Post: 01-07-2011, 05:45 PM
  3. Ambitious Noob Here - Needing Guidance
    By DizzyEwok in forum New To Java
    Replies: 14
    Last Post: 06-28-2009, 09:25 PM
  4. All posts needing mod approval first?
    By xcallmejudasx in forum Suggestions & Feedback
    Replies: 0
    Last Post: 05-26-2009, 04:35 PM
  5. Needing Help!!
    By kingjut06 in forum JDBC
    Replies: 1
    Last Post: 07-07-2007, 11:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •