Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import java.util.*;
- // import java.lang.*;
- // import java.io.*;
- // public class Main {
- // public static void main(String[] args) throws java.lang.Exception {
- // Scanner sc = new Scanner(System.in);
- // int x = sc.nextInt();
- // // int n=sc.nextInt();
- // for (int s = 0; s < x; s++) {
- // int n = sc.nextInt();
- // int a = 1;
- // for (int i = 1; i <= n; i++) {
- // for (int j = a; j <= n / 2; j++) {
- // System.out.print(" ");
- // }
- // for (int k = 1; k <= 2 * a - 1; k++) {
- // System.out.print("*");
- // }
- // System.out.println();
- // if (i <= n / 2) {
- // a++;
- // } else {
- // a--;
- // }
- // }
- // }
- // }
- // }
- // import java.util.*;
- // import java.lang.*;
- // import java.io.*;
- // public class Main {
- // public static void main(String[] args) throws java.lang.Exception {
- // Scanner sc = new Scanner(System.in);
- // int x = sc.nextInt();
- // // int n=sc.nextInt();
- // for (int s = 0; s < x; s++) {
- // int n = sc.nextInt();
- // int a = n / 2;
- // int b = 1;
- // for (int i = 1; i <= n; i++) {
- // for (int j = 1; j <= a; j++) {
- // System.out.print(" ");
- // }
- // for (int k = 1; k <= b; k++) {
- // System.out.print("*");
- // }
- // System.out.println();
- // if (i <= n / 2) {
- // a--;
- // b += 2;
- // } else {
- // a++;
- // b -= 2;
- // }
- // }
- // }
- // }
- // }
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- import java.util.Scanner;
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- //your code here
- Scanner sc=new Scanner(System.in);
- int t=sc.nextInt();
- for(int i = 1; i <= t; ++i) {
- int n=sc.nextInt();
- diamond(n,t);
- }
- }
- static void diamond(int p,int q){
- int row=p/2+1;
- int space=row-1;
- for(int i=1;i<=row;i++){
- for(int j=1;j<=space;j++){
- System.out.print(" "+" ");
- }
- space--;
- for(int j=1;j<=2*i-1;j++){
- System.out.print("*"+" ");
- }
- System.out.println();
- }
- space=1;
- for(int i=1;i<=row-1;i++){
- for(int j=1;j<=space;j++){
- System.out.print(" "+" ");
- }
- space++;
- for(int j=1;j<=2*(row-i)-1;j++){
- System.out.print("*"+" ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement