九九乘法表

打印乘法口诀表

(1)编写一个方法,参数(二维数组),完成将二维数组中的数据按照行列显示的工作。

(2)编写一个测试方法,给出99乘法表,放入到二维数组中,调用(1)中的方法,显示乘法口诀表。

代码:

 1 package experiment;
 2 
 3 public class Multi_nine {
 4     public static void main(String args[]) {
 5         out_shape();
 6     }
 7     //将二维数组中的数据按照行列显示
 8     public static void out_shape() {
 9         int a[][] = assign();
10         for(int i = 0; i < a.length; i++){
11             for(int j = 0; j < a[i].length; j++) {
12                 System.out.print((j + 1) + " * " + (i + 1) +  " = ");
13                 System.out.print(a[i][j] + "	");
14             }
15             System.out.print("
");
16         }
17     }
18     
19     public static int[][] init() {
20         int a[][] = null;
21         a = new int[9][];
22         for(int i = 0; i < a.length; i++) {
23             a[i] = new int[i+1];
24         }
25         return a;
26     }
27     
28     public static int[][] assign() {
29         int a[][] = null;
30         a = init();
31         for(int i = 0; i < a.length; i++){
32             for(int j = 0; j < a[i].length; j++) {
33                 a[i][j] = (i + 1) * (j + 1);
34             }
35         }
36         return a;
37     }
38 }
原文地址:https://www.cnblogs.com/CZT-TS/p/7587611.html