代码如下:
1 /*作者:*** 2 *日期:2016-03-02 3 *功能:用类打印乘法表 4 */ 5 public class ChengFaBiao 6 { 7 public static void main(String []args) 8 { 9 Biao biao=new Biao(); 10 for(int i=1;i<10;i++) 11 { 12 biao.line(i); 13 } 14 } 15 } 16 17 class Biao 18 { 19 public void line(int n) 20 { 21 for(int i=1;i<=n;i++) 22 { 23 System.out.print(i+"X"+n+"="+i*n+" "); 24 } 25 System.out.println(); 26 } 27 }
结果如下:
1 1X1=1 2 1X2=2 2X2=4 3 1X3=3 2X3=6 3X3=9 4 1X4=4 2X4=8 3X4=12 4X4=16 5 1X5=5 2X5=10 3X5=15 4X5=20 5X5=25 6 1X6=6 2X6=12 3X6=18 4X6=24 5X6=30 6X6=36 7 1X7=7 2X7=14 3X7=21 4X7=28 5X7=35 6X7=42 7X7=49 8 1X8=8 2X8=16 3X8=24 4X8=32 5X8=40 6X8=48 7X8=56 8X8=64 9 1X9=9 2X9=18 3X9=27 4X9=36 5X9=45 6X9=54 7X9=63 8X9=72 9X9=81
时间: 2024-10-13 05:41:47