Array implementation matrix adds 1 layers to the inner layer

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.