Package java1701;
public class Javamain {
public static void Main (string[] args) {
level by Layer Plus
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;//graphic width
int[][] arr = new INT[W][W];
for (int ceng = 1; CEng <= (w + 1)/2; ceng++) {
DoWork (CEng, W, arr);//i is a number of layers and numbers
}
Print array
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;
}
}
}
}
This article is from the "10917283" blog, please be sure to keep this source http://10927283.blog.51cto.com/10917283/1900559
Array implementation matrix adds 1 layers to the inner layer