luoni

Christmas Tree

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