Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class dfl07_ChristmasTree{
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int treeHeight = scanner.nextInt();
- for (int i = 0; i <= treeHeight; i++) {
- for (int space = 0; space < (treeHeight - i); space++) {
- System.out.print(" "); // space may replace with other symbols for better view
- }
- for (int j = 0; j <= i-1; j++) { // branches left side
- System.out.print("*");
- }System.out.print(" | "); // log between 2 spaces
- for (int j = 0; j <= i-1; j++) { //branches right side
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment