Advertisement
Joreto

ChristmasTree

Jun 28th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.         int n = Integer.parseInt(scanner.nextLine()); // Number of rows
  8.  
  9.         for (int i = 1; i <= n; i++) {
  10.             // Print spaces
  11.             for (int j = 1; j <= n - i; j++) {
  12.                 System.out.print(" ");
  13.             }
  14.  
  15.             // Print asterisks
  16.             for (int k = 1; k <= 2 * i - 1; k++) {
  17.                 System.out.print("*");
  18.             }
  19.  
  20.             // Move to the next line
  21.             System.out.println();
  22.         }
  23.  
  24.         // Print the trunk
  25.         for (int i = 1; i <= n - 1; i++) {
  26.             System.out.print(" ");
  27.         }
  28.         System.out.println("*");
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement