veronikaaa86

Christmas Tree

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