Advertisement
Dido09

1.4 - Diamond

May 8th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class KDiamond {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int n;
  9. do {
  10. n=scanner.nextInt();
  11. } while(n<4 || n>32);
  12.  
  13.  
  14. for(int i=0;i<n;i++) {
  15. System.out.print(".");
  16. }
  17. for(int i=0;i<n*3;i++) {
  18. System.out.print("*");
  19. }
  20. for(int i=0;i<n;i++) {
  21. System.out.print(".");
  22. }
  23. System.out.println();
  24.  
  25. for(int i=1;i<n;i++) {
  26. for(int j=0;j<n-i;j++) {
  27. System.out.print(".");
  28. }
  29. System.out.print("*");
  30. for(int j=0;j<(n*3)+(i-1)*2;j++) {
  31. System.out.print(".");
  32. }
  33. System.out.print("*");
  34. for(int j=0;j<n-i;j++) {
  35. System.out.print(".");
  36. }
  37. System.out.println();
  38. }
  39.  
  40. for(int i=0;i<n*5;i++) {
  41. System.out.print("*");
  42. }
  43. System.out.println();
  44.  
  45. for(int i=0;i<2*n;i++) {
  46. for(int j=0;j<i+1;j++) {
  47. System.out.print(".");
  48. }
  49. System.out.print("*");
  50. for(int j=0;j<5*n-(2*i)-4;j++) {
  51. System.out.print(".");
  52. }
  53. System.out.print("*");
  54. for(int j=0;j<i+1;j++) {
  55. System.out.print(".");
  56. }
  57. System.out.println();
  58. }
  59.  
  60. for(int i=0;i<2*n+1;i++) {
  61. System.out.print(".");
  62. }
  63. for(int i=0;i<n-2;i++) {
  64. System.out.print("*");
  65. }
  66. for(int i=0;i<2*n+1;i++) {
  67. System.out.print(".");
  68. }
  69.  
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement