首页 > 其他 > 详细

九九乘法表

时间:2017-09-24 17:05:44      阅读:310      评论:0      收藏:0      [点我收藏+]

打印乘法口诀表

(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] + "\t");
14             }
15             System.out.print("\n");
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 }

 

九九乘法表

原文:http://www.cnblogs.com/CZT-TS/p/7587611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!