package java1701;
public class javaMain {
?? ?public static void main(String[] args) {
?? ??? ?// 逐層加
?? ??? ?// 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
?? ??? ?// 1 2 2 2 2 1 1 2 2 2 1 1 2 2 1 1 2 1
?? ??? ?// 1 2 3 3 2 1 1 2 3 2 1 1 2 2 1 1 1 1
?? ??? ?// 1 2 3 3 2 1 1 2 2 2 1 1 1 1 1
?? ??? ?// 1 2 2 2 2 1 1 1 1 1 1
?? ??? ?// 1 1 1 1 1 1
?? ??? ?show();
?? ?}
?? ?public static void show() {
?? ??? ?int w = 11;//圖形寬度
?? ??? ?int[][] arr = new int[w][w];
?? ?
?? ??? ?for (int ceng = 1; ceng <= (w + 1) / 2; ceng++) {
?? ??? ??? ?doWork(ceng, w ,arr);//i是數字層數及數字
?? ??? ?}
?? ??? ?//打印數組
?? ??? ?for (int i = 0; i < arr.length; i++) {
?? ??? ??? ?for (int j = 0; j < arr[i].length; j++) {
?? ??? ??? ??? ?System.out.print(arr[i][j]+" ");
?? ??? ??? ?}
?? ??? ??? ?System.out.println();
?? ??? ?}
?? ?}
?? ?public static void doWork(int ceng, int width,int[][] arr) {
?? ??? ?for (int i = ceng-1; i < width-ceng+1; i++) {
?? ??? ??? ?for (int j = ceng-1; j < width-ceng+1; j++) {
?? ??? ??? ??? ?arr[i][j]=ceng;
?? ??? ??? ?}
?? ??? ?}?? ??? ?
?? ?}
}
轉載于:https://blog.51cto.com/10927283/1900559