打印十字图
来源:互联网 发布:relief 人工智能 编辑:程序博客网 时间:2024/04/29 13:29
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示(可参见p1.jpg)
import java.util.Scanner;public class dibage {public static void main(String[] args) {// TODO Auto-generated method stubScanner 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]; }}}}}
0 0
- 蓝桥杯:打印十字图
- 打印十字图
- 蓝桥杯:打印十字图
- 蓝桥杯:打印十字图
- 34.打印十字图
- 打印十字图
- 打印十字图
- 蓝桥杯 打印十字图
- 打印十字图
- 打印十字图
- 蓝桥杯打印十字图
- 篮桥杯 打印十字图
- 蓝桥杯 打印十字图
- 蓝桥杯:打印十字图
- 蓝桥杯 打印十字图
- 打印十字图
- 打印十字图
- 打印十字图
- Java中编译运行带包名和不带包名的HelloWorld
- poj2135(模板题)
- 高于均分的学生
- 牛客网每日打卡-网络基础-20160406
- CodeForces 6D Lizards and Basements 2(DFS)
- 打印十字图
- 汉诺塔
- DTAM: Dense Tracking and Mapping(一)
- 第75课:Spark SQL基于网站Log的综合案例实战每天晚上20:00YY频道现场授课频道68917580
- GPU&VS2012&CUDA&matlab&Arrayfire杂记(六)——c语言转换
- 基于MFC对话框程序中添加菜单栏
- 登录页面
- 教师工资
- 使用supervisor提高nodejs调试效率