Spiral

zhaozj2021-02-16  72

Back up the old post,:) ------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------- From ChinaJavaworld, the results of my spiral, and I do Everyone pointers.

// This is my first Java program, everyone points to pull, first thank you. / * Spiral Matrix Problem Problem: Programming Generate H * L Spiral Matrix. (For the convenience of programming, we specify H and L not more than 9). H = 5 L = 5 h = 6 l = 3 h = 2 l = 21 2 3 4 5 1 2 3 4 5 6 1 216 17 18 19 6 14 15 16 17 18 7 4 315 24 25 20 7 13 12 11 10 9 814 23 22 21 813 12 11 10 9 * // * ------------------------ My set of results ------- --------------- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1652 53 54 55 56 57 58 59 60 61 62 63 64 65 66 1751 96 97 98 99 100 101 102 103 104 105 106 107 108 67 185 136 137 138 139 140 141 142 109 68 1949 94 131 160 161 162 163 164 165 166 167 168 143 110 69 2048 93 130 159 180 181 182 183 184 185 186 169 144 111 70 2149 192 191 190 189 188 187 170 145 112 71 2246 91 128 175 174 177 172 171 146 113 72 2345 90 127 156 155 154 153 152 151 150 149 148 147 114 73 2444 89 126 125 124 123 122 121 120 119 118 117 116 115 74 2543 88 87 86 85 84 83 82 81 80 79 78 77 76 75 2642 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 ------------------------------------- ------------------------- * ///: Printhelixmatrix.java/** CopyRight (c) Freedebug * 2003-11-21 * Thank u For reading at my code. ^ _ ^ * / class helixmatrix {

int [] [] mymatrix = new int [20] [20];

Static int h = 10;

Static int L = 9;

Static int count = 0;

// Fill the number of numbers

INTHH = H;

// Matrix actual size int L = L;

Int stepx = hh;

// Initial step Int stepy = ll-1; int x = 0;

// Initial coordinate int y = 0;

Void FillFromLettoright (int step) {

For (int i = 0; i

IF (MyMatrix [Y] == 0) {MyMatrix [Y] [x] = count;}

Else {x ; mymatrix [y] [x] = count;}

}

}

Void FillFromuptodown (int steel) {

For (int i = 0; i

y ;

Mymatrix [y] [x] = count;

}

}

Void FillFromrightToleft (int step) {

For (int i = 0; i

X-;

Mymatrix [y] [x] = count;

}

}

Void FillFromDowntoup (int step) {

For (int i = 0; i

Y--

Mymatrix [y] [x] = count;

}

}

Public void make () {

Do {

// From left to right, from top to bottom, from right to left, from bottom to top, each cycle is filled with a circle, it is very well understood. :)

IF (count! = h * L) FillFromLettoright (Stepx -);

IF (count! = h * L) FillFromuptodown (STEPY -);

IF (count! = h * L) FillFromrightToleft (stepx -);

IF (count! = h * L) FillFromDowNtoup (STEPY -);

} while (count! = h * L);

}

Public void prtmatrix () {

// Print out, pay attention to the typography! :)

For (int i = 0; i

For (int J = 0; J

IF (MyMatrix [i] [j] <10) System.out.print ("" mymatrix [i] [j]);

Else IF (MyMatrix [i] [j]> = 100) System.out.print ("" mymatrix [i] [j]);

Else System.Out.print ("" mymatrix [i] [j]);

SYSTEM.OUT.Println ();

}

}

}

Public class printhelixmatrix {

Public static void main (String [] args) {

Helixmatrix aa = new helixmatrix ();

Aa.make ();

Aa.prtmatrix ();

}

}

//: ~ ~