164k views
4 votes
Please help me with the triangle

Please help me with the triangle-example-1

1 Answer

4 votes

Answer:

class Main {

public static void main(String[] args) {

makeATree();

}

private static int TREESIZE = 9;

public static void makeATree() {

String gap = "";

for (int row = TREESIZE; row > 0; row--) {

System.out.print(gap);

gap += " ";

for(int col = 0; col < row; col++) {

System.out.printf("* ");

}

System.out.printf("\\");

}

}

}

Step-by-step explanation:

Here you go. The tree size is a magic number, so I isolated that into a static class variable.

User Virtualmic
by
5.2k points