A two-dimensional array is used for the combination of graphic and digital graphics output sets. Analyze the Excel table first and find the simple rules. The number of rows in a two-dimensional array is row high and the number of columns is the last number size.
For reducing and then increasing and then increasing, you can use a Boolean flag to increase or decrease the state, minimize its flag to the opposite and change the initial value size.
Effect:
Analysis in Excel
Java code:
1 Packagejava_test;2 3 Public classPrintm {4 5 /*6 7 3 78 2 4 6 89 1 5 9Ten Planar graphs (two-dimensional arrays) One A */ - Public Static voidMain (string[] args) { - the intatr[][]=New int[3] [9]; - //generate 9 numbers, put in the corresponding position - Booleanflag=false;//False indicates that the horizontal axis is decreasing, and true represents increasing - //Initial Position + intx=2; - intY=0; + for(inti=1;i<=9;i++){ A at //put the first number in a -atr[x][y]=i; - //y is always increasing -y++; - - if(!flag) {//if x is reduced to make it self-reducing inx--; - } to + if(flag) { -X + +; the } * $ if(x<0) {//x minus 0, minus 1.Panax Notoginsengflag=true; -X=x+2; the } + A if(X>2) {//x plus 2, plus 3. theflag=false; +X=x-2; - } $ } $ - - for(inti=0;i<3;i++){ the for(intJ =0;j<9;j++){ - if(atr[i][j]==0){WuyiSystem.out.print (""); the}Else{ - System.out.print (Atr[i][j]); Wu } - } About System.out.println (); $ } - - - A } +}
Test:
-------------------------------------------------------the transformation of the input n number output m--------------------------------
1 Packagejava_test;2 3 Importorg.junit.Test;4 5 Public classPrintm_duogeshu {6 7 /*8 * 9 * 3 7 2 4 6 8 1 5 9 Planar graphic (two-dimensional array)Ten * One */ A Public Static voidTest1 (intnum) { - - intHeight = (NUM/4) + 1;//4 sides the - intAtr[][] =New int[Height][num]; - //generate 9 numbers, put in the corresponding position - BooleanFlag =false;//False indicates that the horizontal axis is decreasing, and true represents increasing + //Initial Position - intx = height-1; + inty = 0; A for(inti = 1; I <= num; i++) { at - //put the first number in a -Atr[x][y] =i; - //y is always increasing -y++; - in if(!flag) {//if x is reduced to make it self-reducing -x--; to } + - if(flag) { theX + +; * } $ Panax Notoginseng if(x < 0) {//x minus 0, minus 1. -Flag =true; thex = x + 2; + } A the if(x > Height-1) {//x plus 2, plus 3. +Flag =false; -x = x-2; $ } $ } - - for(inti = 0; i < atr.length; i++) { the for(intj = 0; J < Atr[i].length; J + +) { - if(Atr[i][j] = = 0) {WuyiSystem.out.print (""); the}Else { - System.out.print (Atr[i][j]); Wu } - } About System.out.println (); $ } - - } - A @Test + Public voidTest () { thePrintm_duogeshu.test1 (13); - } $}
Test:
Java Print M graphics (two-dimensional arrays)--(ix)