Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class e10_Diamond {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. int LR = (n - 1) / 2;
  9. int mid = ((n - (2 * LR)) - 2);
  10.  
  11. if (n % 2 == 0) {
  12. System.out.print(repeatStr("-", LR));
  13. System.out.print("**");
  14. System.out.println(repeatStr("-", LR));
  15. } else {
  16. System.out.print(repeatStr("-", LR));
  17. System.out.print("*");
  18. System.out.println(repeatStr("-", LR));
  19. }
  20.  
  21. for (int i = 0; i < (n + 1) / 2 - 1; i++) {
  22. if (n % 2 == 0) {
  23. System.out.print(repeatStr("-", LR - i - 1));
  24. System.out.print("*" + repeatStr("-", mid + 2 + 2 * i) + "*");
  25. System.out.println(repeatStr("-", LR - i - 1));
  26. } else {
  27. System.out.print(repeatStr("-", LR - i - 1));
  28. System.out.print("*" + repeatStr("-", mid + 2 * i + 2) + "*");
  29. System.out.println(repeatStr("-", LR - i - 1));
  30. }
  31. }
  32.  
  33. for (int i = (n + 1) / 2 - 2; i > 0; i--) {
  34. if (n % 2 == 0) {
  35. System.out.print(repeatStr("-", LR - i +1)); // LR = (n - 1) / 2;
  36. System.out.print("*" + repeatStr("-", mid + 2 + 2*i) + "*"); // mid = ((n - (2 * LR)) - 2);
  37. System.out.println(repeatStr("-", LR - i -1));
  38. } else {
  39. System.out.print(repeatStr("-", LR - i + 1));
  40. System.out.print("*" + repeatStr("-", mid +2 - i) + "*");
  41. System.out.println(repeatStr("-", LR - i + 1));
  42. }
  43. }
  44.  
  45. if (n % 2 == 0) {
  46. System.out.print(repeatStr("-", LR));
  47. System.out.print("**");
  48. System.out.println(repeatStr("-", LR));
  49. } else {
  50. System.out.print(repeatStr("-", LR));
  51. System.out.print("*");
  52. System.out.println(repeatStr("-", LR));
  53. }
  54. }
  55. static String repeatStr (String text, int countToRepeat) {
  56. StringBuilder result = new StringBuilder();
  57.  
  58. for(int i = 0; i < countToRepeat; i++) {
  59. result.append(text);
  60. }
  61. return result.toString();
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement