纯css打造立体时钟
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
By_jie

打印九九乘法表

【需求说明】:写一段代码实现打印最简九九乘法表

【需求分析】:九九乘法表九行九列

【需求实现】:

 1 /**
 2  * 
 3  */
 4 package edu.aeon.algorithm;
 5 
 6 /**
 7  * @author by lzj
 8  * 创建于: 2017年10月18日 上午11:20:18
 9  * 需求/说明:打印出九九乘法表
10  */
11 public class MultiplicationTable {
12     /**
13      * 第一种方法:使用两个for循环 使用if控制输出格式
14      * at 2017年10月18日 上午11:38:16 by lzj
15      * @parameters1 无
16      * @return void
17      */
18     private static void cfb1() {
19         System.out.println("=========cfb1()==========");
20         for(int i=1;i<=9;i++) {
21             for(int j=1;j<=i;j++) {
22                 if(i*j<10) {
23                 System.out.print(j+" x "+i+" = "+i*j+"   ");
24                 }else {
25                     System.out.print(j+" x "+i+" = "+i*j+"  ");
26                 }
27             }
28             System.out.println();
29         }
30     }
31     /**
32      * 
33      * at 2017年10月18日 下午2:33:11 by lzj
34      * @parameters1 无
35      * @return void
36      */
37     private static void cfb2() {
38         System.out.println("=========cfb2()==========");
39         for(int i=1,j=1;j<=9;i++) {
40             if(i*j<10) {
41                 System.out.print(j+" x "+i+" = "+i*j+"   ");
42                 }else {
43                     System.out.print(j+" x "+i+" = "+i*j+"  ");
44                 }
45             if(i==j) {
46                 i = 0;
47                 j++;
48                 System.out.println();
49                 
50             }
51         }
52     }
53     /**
54      * at 2017年10月18日 上午11:20:18 by lzj
55      * @parameters1 无
56      * @parameters2 无
57      * @return void
58      */
59     public static void main(String[] args) {
60         long a=System.currentTimeMillis();
61         //这里放需要测试执行时间的代码段
62         cfb1();
63         long b=System.currentTimeMillis();
64         cfb2();
65         System.out.println("执行cfb1()耗时 :"+(b-a)/1000f+"秒");
66         System.out.println("执行cfb2()耗时 :"+(System.currentTimeMillis()-b)/1000f+"秒");
67     }
68 
69 }
70 ================【控制台输出】======================
71 =========cfb1()==========
72 1 x 1 = 1   
73 1 x 2 = 2   2 x 2 = 4   
74 1 x 3 = 3   2 x 3 = 6   3 x 3 = 9   
75 1 x 4 = 4   2 x 4 = 8   3 x 4 = 12  4 x 4 = 16  
76 1 x 5 = 5   2 x 5 = 10  3 x 5 = 15  4 x 5 = 20  5 x 5 = 25  
77 1 x 6 = 6   2 x 6 = 12  3 x 6 = 18  4 x 6 = 24  5 x 6 = 30  6 x 6 = 36  
78 1 x 7 = 7   2 x 7 = 14  3 x 7 = 21  4 x 7 = 28  5 x 7 = 35  6 x 7 = 42  7 x 7 = 49  
79 1 x 8 = 8   2 x 8 = 16  3 x 8 = 24  4 x 8 = 32  5 x 8 = 40  6 x 8 = 48  7 x 8 = 56  8 x 8 = 64  
80 1 x 9 = 9   2 x 9 = 18  3 x 9 = 27  4 x 9 = 36  5 x 9 = 45  6 x 9 = 54  7 x 9 = 63  8 x 9 = 72  9 x 9 = 81  
81 =========cfb2()==========
82 1 x 1 = 1   
83 2 x 1 = 2   2 x 2 = 4   
84 3 x 1 = 3   3 x 2 = 6   3 x 3 = 9   
85 4 x 1 = 4   4 x 2 = 8   4 x 3 = 12  4 x 4 = 16  
86 5 x 1 = 5   5 x 2 = 10  5 x 3 = 15  5 x 4 = 20  5 x 5 = 25  
87 6 x 1 = 6   6 x 2 = 12  6 x 3 = 18  6 x 4 = 24  6 x 5 = 30  6 x 6 = 36  
88 7 x 1 = 7   7 x 2 = 14  7 x 3 = 21  7 x 4 = 28  7 x 5 = 35  7 x 6 = 42  7 x 7 = 49  
89 8 x 1 = 8   8 x 2 = 16  8 x 3 = 24  8 x 4 = 32  8 x 5 = 40  8 x 6 = 48  8 x 7 = 56  8 x 8 = 64  
90 9 x 1 = 9   9 x 2 = 18  9 x 3 = 27  9 x 4 = 36  9 x 5 = 45  9 x 6 = 54  9 x 7 = 63  9 x 8 = 72  9 x 9 = 81  
91 执行cfb1()耗时 :0.002秒
92 执行cfb2()耗时 :0.003秒
单击"+"查看源码

 

【需求实现运行结果】:

 

 


 

posted @ 2017-10-18 14:58  1024军团  阅读(275)  评论(0编辑  收藏  举报