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:
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?
Code :
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.
Re: changing character repetition
You nailed it, thank you!