Advertisement
whitestarrr

Untitled

Feb 28th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package p05_Diamond;
  2. import java.util.Scanner;
  3. public class Diamond {
  4. public static void main(String[] args) {
  5. Scanner console = new Scanner(System.in);
  6. int n = Integer.parseInt(console.nextLine());
  7. String dots = repeatStr(".", n);
  8. System.out.println(dots + repeatStr("*", n * 3) + dots);
  9. int dotsCount = n * 3;
  10. int dotsCount2 = n * 5 - 4;
  11.  
  12. for (int i = n; i > 1; i--) {
  13. System.out.println(repeatStr(".", i - 1) + "*" + repeatStr(".", dotsCount) + "*" + repeatStr(".", i - 1));
  14. dotsCount +=2;
  15. }
  16. System.out.println(repeatStr("*", n * 5));
  17. for (int i = 1; i <= n * 2; i++) {
  18. System.out.println(repeatStr(".", i) + "*" + repeatStr(".", dotsCount2) + "*" + repeatStr(".", i));
  19. dotsCount2 -=2;
  20. }
  21. System.out.println(repeatStr(".", n * 2 + 1) + repeatStr("*", n - 2) + repeatStr(".", n * 2 + 1));
  22. }
  23. static String repeatStr(String str, int count) {
  24. StringBuilder sb = new StringBuilder();
  25.  
  26. for (int i = 0; i < count; i++) {
  27. sb.append(str);
  28. }
  29. return sb.toString();
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement