Advertisement
Guest User

ChristmasTree

a guest
Feb 20th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by Jo on 2/18/2017.
  5.  */
  6. public class ChristmasTree {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int treeSize = Integer.parseInt(scanner.nextLine());
  10.  
  11.         for (int i = 0; i <= treeSize; i++) {
  12.             System.out.print(draw(" ", treeSize - i));
  13.             System.out.print(draw("*", i));
  14.             System.out.print(" | ");
  15.             System.out.print(draw("*", i));
  16.             System.out.println();
  17.         }
  18.  
  19.     }
  20.  
  21.     public static String draw(String str, int count) {
  22.         StringBuffer sb = new StringBuffer();
  23.         for (int i = 0; i < count; i++) {
  24.             sb.append(str);
  25.         }
  26.         return sb.toString();
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement