Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.annotation.Repeatable;
- import java.util.Scanner;
- public class ChristmasTree {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int space = 0; space < n ; space++) {
- System.out.print(" ");
- }
- System.out.println(" | ");
- for (int row = 0; row < n ; row++) {
- System.out.print(RepeatStr(" ", n -1 - row ));
- System.out.print(RepeatStr("*", row + 1 ));
- System.out.print(" | ");
- for (int right = 0; right < row + 1 ; right++) {
- System.out.print(RepeatStr("*", right + 1 - right));
- }
- System.out.println();
- }
- }
- static String RepeatStr (String text, int caunt) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < caunt; i++) {
- sb.append(text);
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment