paykova

SnowFlake

Oct 18th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SnowFlake {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8.  
  9. for (int i = 0; i < n - 1; i++) {
  10. String firstAndLastLines = repeatStr(".", i)
  11. + "*"
  12. + repeatStr(".", n - i)
  13. + "*"
  14. + repeatStr(".", n - i)
  15. + "*"
  16. + repeatStr(".", i);
  17. System.out.println(firstAndLastLines);
  18. }
  19.  
  20. String middleLines = repeatStr(".", ((2 * n + 3) - 5) / 2)
  21. + repeatStr("*", 5)
  22. + repeatStr(".", ((2 * n + 3) - 5) / 2);
  23. System.out.println(middleLines);
  24. String staticLine = repeatStr("*", 2 * n + 3);
  25. System.out.println(staticLine);
  26. System.out.println(middleLines);
  27.  
  28. for (int i = 1; i <= n - 1; i++) {
  29. String firstAndLastLine2 = repeatStr(".", n - 1 - i)
  30. + "*"
  31. + repeatStr(".", 1 + i)
  32. + "*"
  33. + repeatStr(".", 1 + i)
  34. + "*"
  35. + repeatStr(".", n - 1 - i);
  36. System.out.println(firstAndLastLine2);
  37. }
  38. }
  39.  
  40. static String repeatStr(String strToRepeat, int count) {
  41. String text = "";
  42. for (int i = 0; i < count; i++) {
  43. text += strToRepeat;
  44. }
  45. return text;
  46. }
  47. }
Add Comment
Please, Sign In to add comment