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 out
So, you need to create a small block. What information does that block need? Just the maximum. But the recursion needs to know what line its on... you end up with a constructor like:
public void printTriangle (int current, int max)
Now, use that to put the rest of the recursion together:
public void printTriangle (int current, int max)
{
if (current <= max)
{
// Draw the line of stars...
for (int x=0; x
Now, all you have to do, is initiate it:
printTriangle(1, 5);