Advertisement
Evilerus

choinka

Oct 4th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. package tk.evilus;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class choinka {
  6.     public static void main(String[] arg) {
  7.         int a, h;
  8.         char star = '*';
  9.         System.out.print("Enter the height of the Christmas tree: ");
  10.         Scanner input = new Scanner(System.in);
  11.         h = input.nextInt();
  12.         input.close();
  13.         for (int i = 0; i <= h; i++) {
  14.             if (i != h) {
  15.                 for (a = 0; a < h * 2; a++) {
  16.                     if (a < (h - i) || a > (h + i)) {
  17.                         System.out.print(" ");
  18.  
  19.                     } else {
  20.                         System.out.print(star);
  21.  
  22.                     }
  23.                 }
  24.             } else {
  25.                 for (a = 0; a<h*2; a++) {
  26.                     if (a<h || a>h)
  27.                         System.out.print(" ");
  28.                     else
  29.                         System.out.print("#");
  30.                 }
  31.             }
  32.  
  33.             System.out.println();
  34.  
  35.         }
  36.        
  37.  
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement