Name: Anonymous 2012-02-18 22:23
Is it possible to convert the following iteration code into a recursion one?
public static void triangle(int m, int n)
{
if(m<=n)
{
int x =0;
int y =0;
while(x<m)
{
System.out.print("*");
x++;
}
System.out.print("\n");
triangle(m + 1,n);
while(y<m)
{
System.out.print("*");
y++;
}
System.out.print("\n");
}
}
The output is an asterisks of a triangle.
public static void triangle(int m, int n)
{
if(m<=n)
{
int x =0;
int y =0;
while(x<m)
{
System.out.print("*");
x++;
}
System.out.print("\n");
triangle(m + 1,n);
while(y<m)
{
System.out.print("*");
y++;
}
System.out.print("\n");
}
}
The output is an asterisks of a triangle.