Hi, I'm trying to output figures of Christmas trees using a method that accepts two parameters, segment and height. I just can't get the spacing right!!! They should be centered, and I can only use very basic level
Java. Thank you so much for any help!!
public class ChristmasTrees
{
public static void main(
String[] args)
{
drawTree(3, 4);
System.out.println();
drawTree(2, 5);
}
public static void drawTree(int segments, int height)
{
for (int i = 1; i <= segments; i++)
{
for (int line = 1; line <= height; line++)
{
for (int spaces = 0; spaces <= (height - line); spaces++)
{
System.out.print(" ");
}
for (int dots = 1; dots <= (2*line - 1) + 2*(i-1); dots++)
{
System.out.print("*");
}
System.out.println();
}
}
System.out.println(" * ");
System.out.println(" * ");
System.out.println(" ******* ");
}
}