Results 1 to 4 of 4
  1. #1
    passingTime is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default Repeating a letter

    Hello,

    Is there any way to repeat something over and over on the same line?

    For example (and i know this is wrong but something like this):

    int amount = 5

    String toRepeat = "d"

    print d amount times

    ---------------------------------------------

    so it would end up showing: ddddd

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    When you need to repeat things in Java, think loops. when you know in advance how many times you'll be repeating it, think for loop, and that's what I suggest here, a for loop.

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    354
    Rep Power
    5

    Default

    Java Code:
     int amount = 5;
    
    String toRepeat = "d";
    
    String newString="";
    
    for(int i=0; i<amount; i++){
    newString=newString+toRepeat;
    }
    
    System.out.println(newString);

  4. #4
    passingTime is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 02-11-2011, 05:57 AM
  2. jxl repeating rows
    By mermaid in forum New To Java
    Replies: 0
    Last Post: 01-14-2011, 03:59 PM
  3. Repeating
    By AbdulAziz Bader in forum New To Java
    Replies: 3
    Last Post: 05-05-2010, 11:35 PM
  4. Repeating Do-While Statement
    By adamg106 in forum New To Java
    Replies: 10
    Last Post: 04-22-2010, 07:09 AM
  5. adjacent repeating letters
    By artemis_r2 in forum New To Java
    Replies: 1
    Last Post: 11-17-2007, 04:48 AM

Posting Permissions

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