爱程序网

【Java_Base】九九乘法表

来源: 阅读:

 

 案例一

1
class Multiplication{ 2 public static void main(String args[]){ 3 String Str = "9 9 乘法表\n"; 4 Str += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; 5 System.out.println(Str); 6 for(int i=1;i<10;i++){ 7 for(int j=1;j<=i;j++){ 8 //打印乘法表 9 System.out.print(j+"×"+i+"="+i*j); 10 //添加逗号 11 if(i!=j){ 12 System.out.print(","); 13 } 14 } 15 //每打印一行输出一个换行符 16 System.out.print("\n"); 17 } 18 } 19 }


案例二

 1 public class Multiplication_Table {
 2 
 3     public static void main(String[] args) {
 4 
 5         String Str = "9 9 乘法表\n";
 6         Str += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
 7         for (int i = 1, j = 1; i < 10; j++) {
 8             Str += "\t"+ j + "*" + i + "=" + j * i;
 9             if (i == j) {
10                 j = 0;
11                 i++;
12                 Str += "\n";
13             }
14         }
15         System.out.println(Str);
16     }
17 }

 



 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助