I need to to write a method that is called like printTriangle(5);
. We need to create an iterative method and a recursive method (without ANY iteration). The output needs to look like this:
*
**
***
****
*****
This code works with the iterative but I can't adapt it to be recursive.
public void printTriangle (int count) {
int line = 1;
while(line <= count) {
for(int x = 1; x <= line; x++) {
System.out.print("*");
}
System.out.print("\n");
line++;
}
}
I should note that you cannot use any class level variables or any external methods.
Thanks.