public class Main
{
public static void pyr(int n)
{
for(int i=1;i<=n;i++)
{
for(int j = 1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Can such a code for a pyramid like shape of asteriks be implemented recursively ? if so especially the 2 loops as the first one is for leveling while the second is used to fill each level.
The answer is yes – basically everything iterative can be done recursively, sometimes it is much easier, but more time consuming.
For your question – this does the trick: