Program: Print multiplication tables
(1) Write a method, a parameter (a two-dimensional array), to complete the work of displaying the data in a two-dimensional array in rows and columns.
(2) Write a test method, give 99 multiplication table, put into a two-dimensional array, call the method in (1), display the multiplication table.
The class of the Description:main method is given at the end, and the code is as follows:
1 /*2 *description: Defines a tool class, responsible for initializing two-dimensional arrays and printing two-dimensional arrays3 *4 * */5 6 Packagetools;7 8 9 Public classOperate {Ten One //initialize a two-dimensional array A Public Staticstring[][] Init () { - -string[][] Temp =NewString[9][9]; the for(inti = 0; I < 9; i++ ) { - - for(intj = 0; J < 9; J + + ) { - if(J <= i) {//Save multiplication Table contents +TEMP[I][J] = (j + 1) + "*" + (i + 1) + "=" + ((i+1) * (j+1)) + ""; - } + Else { ATEMP[I][J] = "";//where you don't need to assign a value of: "" at } - } -Temp[i][i] + = "\ n";//Add carriage return - } - - returnTemp//returns a two-dimensional array in } - to + //Print array elements - Public Static voidprintinfo (string[][] temp) { the * for(inti = 0; i < temp.length; i++ ) { $ Panax Notoginseng for(intj = 0; J < Temp[i].length; J + + ) { - System.out.print (Temp[i][j]); the } + } A } the +}
1 /*2 * Description: 99 multiplication Table printed with two-dimensional array3 * 4 * Written By:cai5 * 6 * Date written;7 * 8 * */9 Ten Packagemain; One A Importtools. Operate; - - Public classDEMOTWO2 { the - Public Static voidMain (String args[]) { - -string[][] temp = Operate.init ();//initialize a two-dimensional array +Operate.printinfo (temp);//Print Array - + } A}
Java Experimental Project Two--two-dimensional array implementation 99 multiplication table