Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine()); // Number of rows
- for (int i = 1; i <= n; i++) {
- // Print spaces
- for (int j = 1; j <= n - i; j++) {
- System.out.print(" ");
- }
- // Print asterisks
- for (int k = 1; k <= 2 * i - 1; k++) {
- System.out.print("*");
- }
- // Move to the next line
- System.out.println();
- }
- // Print the trunk
- for (int i = 1; i <= n - 1; i++) {
- System.out.print(" ");
- }
- System.out.println("*");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement