Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Solution {
- public static void main(String args[])
- {
- Scanner in = new Scanner(System.in);
- int N = in.nextInt();
- char mat[][] = new char[N][N];
- int lh = 0, lb = N - 1, cg = 0, cd = N - 1;
- int max = N;
- char aff = 'O';
- while (cg <= N/2) {
- aff = reverseChar(aff);
- for (int i = 0+N-max; i < max; i++) // lh
- mat[lh][i] = aff;
- for (int i = 0+N-max; i < max; i++)
- mat[lb][i] = aff;
- for (int i = 0+N-max; i < max; i++)
- mat[i][cg] = aff;
- for (int i = 0+N-max; i < max; i++)
- mat[i][cd] = aff;
- lh++;
- lb--;
- cg++;
- cd--;
- max--;
- }
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < N; j++)
- System.out.print(mat[i][j]);
- System.out.println();
- }
- }
- public static char reverseChar(char x)
- {
- if(x == '#')
- return 'O';
- else
- return '#';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement