打印十字图

小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示(可参见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];                                
                }
			}
		}
		
		

	}
	

	

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值