Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: changing character repetition

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default changing character repetition

    is it possible to use two arguments in a recursive method to change the indentation & the amount of repetition of a character without using a loop?

    If the recursive method was called twice, here's an example output of two lines if both arguments of the method were changed:

    gggggg
          gggggggggggg
    Last edited by vendetta; February 12th, 2010 at 08:32 PM. Reason: added code tags


  2. #2
    Member
    Join Date
    Feb 2010
    Location
    Auburn, AL
    Posts
    31
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: changing character repetition

    I'm not really sure what you mean by this.

    In theory, anything you can do with a loop you can do with recursion, and vice versa. So the answer is probably yes. Is something like this what you're asking about?

    printRecursive(characters: integer, indent: integer)
    1. if indent > 0
    2.   then print indentation symbol
    3.   printRecursive(characters, indent - 1)
    4. else if characters > 0 
    5.   then print character symbol
    6.   printRecursive(characters - 1, 0)

    The translation to Java is pretty straightforward. Let me know if this helps answer your question.
    Let me know what you think of my website:
    http://www.auburn.edu/~carpept
    Comments or suggestions are appreciated!

  3. The Following User Says Thank You to CT&SC For This Useful Post:

    vendetta (February 16th, 2010)

  4. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: changing character repetition

    You nailed it, thank you!

Similar Threads

  1. changing the splitpane's cursor
    By chronoz13 in forum AWT / Java Swing
    Replies: 2
    Last Post: February 8th, 2010, 12:11 PM
  2. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM
  3. Help With Java - Changing a File
    By RonenIL in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 5th, 2010, 02:34 AM
  4. Parameter's value is never changing
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 27th, 2009, 05:29 AM