Advertisement
unknown_0711

Untitled

Feb 23rd, 2023
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. // import java.util.*;
  2. // import java.lang.*;
  3. // import java.io.*;
  4.  
  5. // public class Main {
  6. // public static void main(String[] args) throws java.lang.Exception {
  7. // Scanner sc = new Scanner(System.in);
  8. // int x = sc.nextInt();
  9. // // int n=sc.nextInt();
  10. // for (int s = 0; s < x; s++) {
  11.  
  12. // int n = sc.nextInt();
  13. // int a = 1;
  14. // for (int i = 1; i <= n; i++) {
  15.  
  16. // for (int j = a; j <= n / 2; j++) {
  17. // System.out.print(" ");
  18. // }
  19. // for (int k = 1; k <= 2 * a - 1; k++) {
  20. // System.out.print("*");
  21. // }
  22. // System.out.println();
  23.  
  24. // if (i <= n / 2) {
  25. // a++;
  26. // } else {
  27. // a--;
  28. // }
  29. // }
  30. // }
  31. // }
  32. // }
  33.  
  34.  
  35. // import java.util.*;
  36. // import java.lang.*;
  37. // import java.io.*;
  38.  
  39. // public class Main {
  40. // public static void main(String[] args) throws java.lang.Exception {
  41. // Scanner sc = new Scanner(System.in);
  42. // int x = sc.nextInt();
  43. // // int n=sc.nextInt();
  44. // for (int s = 0; s < x; s++) {
  45.  
  46. // int n = sc.nextInt();
  47. // int a = n / 2;
  48. // int b = 1;
  49. // for (int i = 1; i <= n; i++) {
  50.  
  51. // for (int j = 1; j <= a; j++) {
  52. // System.out.print(" ");
  53. // }
  54. // for (int k = 1; k <= b; k++) {
  55. // System.out.print("*");
  56. // }
  57. // System.out.println();
  58.  
  59. // if (i <= n / 2) {
  60. // a--;
  61. // b += 2;
  62. // } else {
  63. // a++;
  64. // b -= 2;
  65. // }
  66. // }
  67. // }
  68. // }
  69. // }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. import java.util.*;
  81. import java.lang.*;
  82. import java.io.*;
  83. import java.util.Scanner;
  84.  
  85. public class Main
  86. {
  87. public static void main (String[] args) throws java.lang.Exception
  88. {
  89. //your code here
  90. Scanner sc=new Scanner(System.in);
  91. int t=sc.nextInt();
  92. for(int i = 1; i <= t; ++i) {
  93. int n=sc.nextInt();
  94. diamond(n,t);
  95. }
  96. }
  97. static void diamond(int p,int q){
  98.  
  99. int row=p/2+1;
  100. int space=row-1;
  101. for(int i=1;i<=row;i++){
  102. for(int j=1;j<=space;j++){
  103. System.out.print(" "+" ");
  104. }
  105. space--;
  106. for(int j=1;j<=2*i-1;j++){
  107. System.out.print("*"+" ");
  108. }
  109. System.out.println();
  110. }
  111. space=1;
  112. for(int i=1;i<=row-1;i++){
  113. for(int j=1;j<=space;j++){
  114. System.out.print(" "+" ");
  115. }
  116. space++;
  117. for(int j=1;j<=2*(row-i)-1;j++){
  118. System.out.print("*"+" ");
  119. }
  120. System.out.println();
  121. }
  122.  
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement