File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ class Solution
6+ {
7+ public static void main (String [] args ) throws Exception {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
9+ StringTokenizer st = new StringTokenizer (br. readLine());
10+
11+ int N = Integer . parseInt(st. nextToken());
12+ if (N == 1 ) {
13+ System . out. println(' *' );
14+ return ;
15+ }
16+ int row = 4 * N - 1 ;
17+ int col = 4 * N - 3 ;
18+ char [][] board = new char [row][col];
19+ for (int i = 0 ; i < row; i++ ) {
20+ Arrays . fill(board[i], ' ' );
21+ }
22+ int cnt = 0 ;
23+ for (int c = 0 ; c < N ; c++ ) {
24+ for (int i = cnt; i < row- cnt; i++ ) {
25+ board[i][cnt] = ' *' ;
26+ board[i][col- cnt- 1 ] = ' *' ;
27+ }
28+ for (int j = cnt; j < col- cnt; j++ ) {
29+ board[cnt][j] = ' *' ;
30+ board[row- cnt- 1 ][j] = ' *' ;
31+ }
32+ cnt += 2 ;
33+ }
34+
35+ for (int i = 1 ; i < col/ 2 + 1 ; i++ ) {
36+ if (i % 2 == 0 ) board[i][col- i] = ' *' ;
37+ else board[i][col- i] = ' ' ;
38+ }
39+
40+ for (int i = 0 ; i < row; i++ ) {
41+ for (int j = 0 ; j < col; j++ ) {
42+ if (i == 1 && j > 0 ) continue ;
43+ System . out. print(board[i][j]);
44+ }
45+ System . out. println();
46+ }
47+ }
48+ }
49+
50+ ```
You can’t perform that action at this time.
0 commit comments