Nothing today, I remembered two programs that were impressed when I was studying in the school: Print 99 multiplication table and the solution of 9 palace. 99 Multiplication Table, let me know that the original For can also be used in two layers; the one of the 9 palace pictures, the time written is a 4x4 (in actually 16 palace), running on the school's broken machine 2 minutes More, I got a few thousand solutions; remember Zhang Shaishu (嘿, don't hit me) I don't believe there have so many results. Oh, I haven't been there for a long time. Miss life in school! I miss the day of playing the Red Police Warcraft, playing football!
// 99 Multiplication Table Public Class Table9Mult9 {Public Static Void Main (String [] args) {for (int i = 1; i <10; i ) {for (int J = 1; j <10; j ) {ix J <= i) System.out.Print (j "*" i "=" (i * j) ""); if (i == j) System.out.print ("/ n" }}}}
// 宫 图 p p; 9 9 9 9 将 将 将 将 将 将 将 将 将 将 将 将; 子 图 子 子; 子; 子 子 子 子 子 子 子 子 子 子 子 子; 子 子;;; 子;; 子; 9 lattice private string stars; private static int getaverage () {int sum = 0; for (int i = 1; i <= 9; i ) {SUM = I;} returnium / 9;} Public grid9 () {resultSnum = 0; AVGE = getaverage (); avg3times = average * 3; stars = "------------------"; for (int i = 0; I <9; i ) {grid [i] = 0;}} // Construct Gird Public Void GenerateGrid (Int i, Int J, INT K, INT II, INT JJ, INT KK, INT III, INT JJJ , int KKK) {IF (i! = j && i! = k && i! = II && i! = jj &&i! = kk && i! = iii && i! = jjj &&i! = kkk && j! = K && J! = II && J! = JJ && J! = KK && J! = III && J! = JJJ && J! = KKK && K! = II && K! = JJ && K! = KK && K! = III && K! = JJJ && K! = KKK && II! = JJ && II! = KK && II! = III && II! = JJJ && II! = KKK && JJ! = KK && JJ! = III && JJ! = JJJ && JJ! = KKK && KK! = III && KK! = JJJ && KK! = KKK && III! = JJJ && III! = KKK && JJJ! = KKK) {Grid [0] = i; grid [1] = j; grid [2] = k; grid [3] = II; Grid [4] = JJ; Grid [5] = KK;
Grid [6] = iii; grid [7] = jjj; grid [8] = kkk;} else {for (int index = 0; index <9; index ) {grid [index] = 0;}} // Print Grid Public Void PrintGrid () {for (int i = 1; i <= 9; i ) {system.out.print (Grid [i-1] ""); if (i% 3 == 0) { System.out.print ("/ n");}} system.out.println (stars);} // Get the first line of sum, the following sequential public int get1row () {return grid [0] Grid [1 ] Grid [2];} public int GET2ROW () {Return Grid [3] Grid [4] Grid [5];} public int GET3ROW () {Return Grid [6] Grid [7] Grid [ 8];} // Get column and public int GET1COL () {return Grid [0] Grid [3] Grid [6];} public int GET2COL () {Return Grid [1] Grid [4] Grid [7];} public int GET3COL () {Return Grid [2] Grid [5] Grid [8];} // Get Cross and Public Int Get1X () {Return Grid [0] Grid [4 ] Grid [8];} public int GET2X () {Return Grid [2] Grid [4] Grid [6];} // Judgment, etc. Each line == Each column == Cross and Public Boolean ISequal () {Return (Get1Row () == Avg3TimeS & & Get2Row () == avg3times && get1col () == avg3times && get2col () == avg3times && get1x () == avg3Times && get2x () == avg3times);} // Get results: public int getResultsnum () {RETURN RESULTSNUM;} // The most stupid method - traversing public void getResults () {for (int i = 1; i <10; i ) {for (int J = 1; j <10; j ) {for INT K = 1; K <10; k ) {for (int II = 1; II <10; II
) {For (int JJ = 1; JJ <10; JJ ) {for (int KK = 1; KK <10; KK ) {for (int III = 1; III <10; III ) {for (int JJJ = 1; JJJ <10; JJJ ) {for (int KKK = 1; KKK <10; KKK ) {GenerateGrid (i, j, k, ii, jj, kk, iii, jjj, kkk); if (ISEqual ()) {printGrid (); resultsNum ;}}}}}}}}}}} public static void main (String [] args) {Grid9 grid9 = new Grid9 (); System.out.println ( "starting. .. "); Grid9.getResults (); system.out.println (" end "); system.out.println (" Results Number: " Grid9.getResultsnum ());}}