Advertisement
Ivakis

Триъгълник

Sep 14th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  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 * 4 + 1);
  10. System.out.println(firstline);
  11.  
  12. for (int i = 0; i < n; i++) {
  13. String line = repeatStr(".", 1 + i)
  14. + repeatStr("#", (2 * n - 1) - i * 2)
  15. + repeatStr(" ", 1 + i * 2)
  16. + repeatStr("#", (2 * n - 1) - i * 2)
  17. + repeatStr(".", 1 + i);
  18.  
  19. if(i == n / 2){
  20. line = repeatStr(".", 1 + i)
  21. + repeatStr("#", (2 * n - 1) - i * 2)
  22. + repeatStr(" ", (1 + i * 2) / 2 - 1)
  23. + "(@)"
  24. + repeatStr(" ", (1 + i * 2) / 2 - 1)
  25. + repeatStr("#", (2 * n - 1) - i * 2)
  26. + repeatStr(".", 1 + i);
  27.  
  28. }
  29. System.out.println(line);
  30.  
  31. }
  32. for (int i = 0; i < n; i++) {
  33. String lastPart = repeatStr(".", n + 1 + i)
  34. + repeatStr("#", n * 2 - 1 - 2 * i)
  35. + repeatStr(".", n + 1 + i);
  36. System.out.println(lastPart);
  37. }
  38.  
  39. } public static String repeatStr(String strToRepeat, int count) {
  40. String text = "";
  41. for (int i = 0; i < count; i++) {
  42. text += strToRepeat;
  43. }
  44. return text;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement