码迷,mamicode.com
首页 > 编程语言 > 详细

【Java_Base】九九乘法表

时间:2015-12-26 13:22:20      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

 

 案例一

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 }

 

技术分享


 

【Java_Base】九九乘法表

标签:

原文地址:http://www.cnblogs.com/JayAnother/p/Java.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!