九九乘法表

一、for循环实现:

1 public static void main(String[] args) {
2    int m,n;
3    for(m=1;m<=9;m++){
4       for(n=1;n<=m;n++){
5         System.out.print(n + "x" + m + "=" + m * n + "\t");
6       }
7         System.out.println();
8    }
9 }

 运行结果如下:

 二、while循环实现:

 1 public static void main(String[] args) {
 2     int i =1;
 3     while( i<=9){
 4         int j = 1;
 5         while(j<=i){
6        j++;
7 System.out.print(j+"x"+i+"="+i*j+"\t");
8 } 9    i++; 10    System.out.println(); 11 } 12 }

 

 运行结果如下:

 

posted @ 2018-08-19 15:43  一辈子de赌注  阅读(143)  评论(0编辑  收藏  举报