PoeticalJustice

导航

while and for 2

 1 public class TestWhileAndFor2 {
 2 
 3     /**
 4      * 九九乘法表
 5      * 1!+2!+3!+....+10!=?
 6      *  
 7      */
 8     public static void main(String[] args) {
 9         /*
10         for(int i=1;i<=9;i++){
11             for(int j=1;j<=i;j++){
12                 System.out.print(j+"*"+i+"="+(j*i)+"\t");
13                 }
14             System.out.println();
15         }
16         */
17         //1!+2!+3!+....+10!=?
18         long sum=1;
19         long total=0;
20         for(int j=1;j<=10;j++){
21             sum=sum*j;
22             total+=sum;
23             System.out.println(j+"!="+sum);
24         }
25         
26         System.out.println(" 1!+2!+3!+....+10!="+total);
27         
28         //1+2+3..+10=?
29         long count=0;
30         for(int i=1;i<=10;i++){
31             count+=i;
32         }
33         System.out.println(count);
34     }
35     
36 
37 }

 

posted on 2017-09-28 21:47  PoeticalJustice  阅读(122)  评论(0编辑  收藏  举报