Advertisement
veronikaaa86

ChristmasTree

Oct 16th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ChristmasTree1 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int spaces = n;
  10.         for (int i = 0; i <= n; i++) {
  11.             System.out.println(repeatString(" ", spaces) +
  12.                     repeatString("*", i) +
  13.                     " | " +
  14.                     repeatString("*", i));
  15.             spaces--;
  16.         }
  17.     }
  18.     static String repeatString(String toRepeat, int count) {
  19.         StringBuilder text = new StringBuilder();
  20.  
  21.         for (int i = 1; i <=count; i++) {
  22.             text.append(toRepeat);
  23.         }
  24.         return text.toString();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement