使用for循环嵌套实现乘法口诀表

来源:互联网 发布:网络英语外教一对一 编辑:程序博客网 时间:2024/05/20 05:26

九九乘法表的实现:

package com.liaojianya.chapter1;/** * This program demonstrates the way of using  * for-loop to implement the multiplication tables.   * @author LIAO JIANYA * 2016年7月19日 */public class ForDemo{public static void main(String[] args){for(int i = 1; i < 10; i++){for(int j = 1; j <= i; j++){System.out.print(i + "*" + j + "=" + (i * j) + "\t");}System.out.println();}}}

  运行结果:

1*1=12*1=22*2=43*1=33*2=63*3=94*1=44*2=84*3=124*4=165*1=55*2=105*3=155*4=205*5=256*1=66*2=126*3=186*4=246*5=306*6=367*1=77*2=147*3=217*4=287*5=357*6=427*7=498*1=88*2=168*3=248*4=328*5=408*6=488*7=568*8=649*1=99*2=189*3=279*4=369*5=459*6=549*7=639*8=729*9=81

  分析:整个程序执行1+2+3+...+9 = 45次循环

0 0
原创粉丝点击