Hello,
i am now trying to draw a tree with stars using for loop. I find a code for this but i did not get the logic of the code. Please can anybody explain it to me ? The code is below:
public class DrawingTree {
public static void main(String[]args)
{
int n = 5;
int spaces = n-1;
int ast;
for(int i = 0; i < n; i++)
{
ast = 2*i+1;
for(int j = 1; j <= spaces+ast; j++)
{
if(j <= spaces)
System.out.print(' ');
else
System.out.print('*');
}
System.out.println();
spaces--;
}
}
}