Assume the availability of a method named makeLine that can be passed a non-negative integer n and a character c and return a String consisting of n identic
I won't give you the answer, but hopefully this gives you some hints. A recursive method is something that solves a problem by calling itself to solve a smaller version of the same problem. In your case, the problem is to print this (I've put b
where blanks belong):
OOOOO
bOOO
bbO
You're printing the first line, then solving a smaller version of the same problem, which is to print a smaller triangle:
bOOO
bbO
The problem is that this smaller version isn't quite the same; it has to have extra spaces before each line. How much extra space? Well, that's why the instructor said "use k
to your advantage". How could you call the method recursively, and use k
to tell it to display extra spaces?