Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to output the following array with java array
How to output the following array with java array
To realize the output of the matrix, you need to use a two-bit array in java, for example:

Common class array test {

Private int[][] array;

Public void matrix(int n){// generating matrix

array = new int[n][n];

for(int I = 0; I & ltn;; i++){

for(int j = 0; j & ltn; j++){

//Find the first line

if(i==0){

//Find the value of odd digits, and the value of even digits is the left element plus 1.

if(j%2==0){

array[I][j]=(j+ 1)*(j+ 1);

} Otherwise {

array[I][j]= array[I][j- 1]+ 1;

}

}

//Find the first column

else if(j==0){

if(i%2== 1){

array[I][j]=(I+ 1)*(I+ 1);

} Otherwise {

array[I][j]= array[I- 1][j]+ 1;

}

} Otherwise {

If (i & gtj){

//Looking for patterns

//Even number is +j, the first element of this line.

//Odd bits are the first element of this line -j

if(i%2==0){

Array [I][j]= array [i] [0]+j;

} Otherwise {

array[I][j]= array[I][0]-j;

}

} Otherwise {

if(j%2==0){

array[I][j]= array[0][j]-I;

} Otherwise {

Array [I][j]= array [0] [j]+i;

}

}

}

}

}

for(int I = 0; I & ltn;; i++){

for(int j = 0; j & ltn; j++){

system . out . print(array[I][j]+" ");

}

system . out . println();

}

}

}

The output results are as follows:

1 2 9 10 25

4 3 8 1 1 24

5 6 7 12 23

16 15 14 13 22

17 18 19 20 2 1