小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示(可参见p1.jpg)
import java.util.Scanner;
public class dibage {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int line = scan.nextInt();
shuzu(line);
}
//定义一个二维数组,赋值为 $ 然后找 dian的位置 。
public static void shuzu(int n) {
int num = 5 + 4 * n, s = 0;
char[][] arr = new char[num][num];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
arr[i][j] = '$';
}
}
show(arr);
dayin(arr);
}
public static void dayin(char[][] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
System.out.print(arr[i][j]);
}
System.out.print("\n");
}
}
public static void show(char[][] arr)
{
int lain = arr.length / 2 + 1;
for (int count = 0; count < lain; count += 2)
{
for (int i = count; i < lain; i++)
{
for (int j = count; j < lain; j++)
{
//对角线
if (i == 0 && j == 0 || i == j && i % 2 == 1) {
arr[i][j] = '.';
}
//
if (i == count + 1 && j > 2 + count) {
arr[i][j] = '.';
}
if (j == count + 1 && i > 2 + count) {
arr[i][j] = '.';
}
if (i == count - 1 && j < count) {
arr[i][j] = '.';
}
if (j == count - 1 && i < count) {
arr[i][j] = '.';
}
if (i == count + 1 && j < 2 + count) {
arr[i][j] = '.';
}
if (j == count + 1 && i < 2 + count) {
arr[i][j] = '.';
}
}
}
//右上角
for(int i=0+count,x=0+count;i<lain;i++,x++)
{
for(int j=lain,y=lain-2;j<arr.length-count;j++,y--)
{
arr[i][j] = arr[x][y];
}
}
//左下角
for (int i = lain, x=lain - 2; i < arr.length - count; i++ , x--) {
for (int j = count , y = count; j < lain ; j++ , y++) {
arr[i][j]= arr[x][y] ;
}
}
//右下角
for (int i = lain, x=lain - 2; i < arr.length - count; i++ , x--) {
for(int j=lain,y=lain-2;j<arr.length-count;j++,y--)
{
arr[i][j] = arr[y][x];
}
}
}
}
}