Advertisement
prashandip

Tree

Nov 26th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. public class Tree {
  2.     public static void main(String[] args) {
  3.         Scanner s = new Scanner(System.in);
  4.         System.out.println("Enter the no. of treetop rows:");
  5.         int rows = s.nextInt();
  6.  
  7.         for (int i = 1; i <= rows; i++) {
  8.             for (int space = 0; space < rows - i; space++) {
  9.                 System.out.print("  ");
  10.             }
  11.             for (int j = 1; j <= 2 * i - 1; j++) {
  12.                 System.out.print("* ");
  13.             }
  14.             System.out.println();
  15.         }
  16.  
  17.         for (int i = 0; i < 2; i++) {
  18.             for (int space = 0; space < rows - 2; space++) {
  19.                 System.out.print("  ");
  20.             }
  21.             for (int j = 0; j < 3; j++) {
  22.                 System.out.print("* ");
  23.             }
  24.             System.out.println();
  25.         }
  26.         s.close();
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement