R_Manolova

Christmas tree

Jan 12th, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class dfl07_ChristmasTree{
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int treeHeight = scanner.nextInt();
  7.  
  8.         for (int i = 0; i <= treeHeight; i++) {
  9.             for (int space = 0; space < (treeHeight - i); space++) {
  10.                 System.out.print(" ");         // space may replace with other symbols for better view
  11.             }
  12.             for (int j = 0; j <= i-1; j++) {   // branches left side
  13.                 System.out.print("*");
  14.  
  15.             }System.out.print(" | ");         // log between 2 spaces
  16.  
  17.             for (int j = 0; j <= i-1; j++) {   //branches right side
  18.                 System.out.print("*");
  19.             }
  20.             System.out.println();
  21.         }
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment