Untitled
import java.io.BufferedReader; import java.io.IOException; import java.util.*; import java.io.InputStreamReader; public class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s1 = br.readLine().split(" "); int t = Integer.parseInt(s1[0]); while(t-- > 0){ s1 = br.readLine().split(" "); int n = Integer.parseInt(s1[0]); char[][] arr = new char[n][n]; for(char[] a: arr){ Arrays.fill(a,' '); } int mid = 0; if(n% 2 == 0){ mid = n/2; } else{ mid = n/2 + 1; } boolean flag = true; for(int i = 0;i<mid;i++){ if(flag){ pattern(arr,i,i,n-2*i-1); flag = false; } else{ arr[i+1][i] = '*'; flag = true; } } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ System.out.print(arr[i][j]+" "); } System.out.println(); } } } public static void pattern(char[][] arr, int row, int col, int len){ //System.out.println(row+" "+col+" "+len); for(int i = col;i<=col+len;i++){ arr[row][i] = '*'; //top arr[row+len][i] = '*'; //bottom } for(int i = row; i <= row + len;i++){ arr[i][col+len] = '*'; //right arr[i][col] = '*'; //left } arr[row+1][col] = ' '; } }
Leave a Comment