标签:static oid print demo ati 乘法表 嵌套 out pre
需求:
打印出9x9乘法表:
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
......
可以使用for循环嵌套:
public class forDemo {
public static void main(String[] args) {
for(int x=1;x<=9;x++) {
for(int y=1;y<=x;y++) {
System.out.print(x+"X"+y+"="+x*y+"\t");
}
System.out.println();
}
}
}
打印如下:
1X1=1
2X1=2 2X2=4
3X1=3 3X2=6 3X3=9
4X1=4 4X2=8 4X3=12 4X4=16
5X1=5 5X2=10 5X3=15 5X4=20 5X5=25
6X1=6 6X2=12 6X3=18 6X4=24 6X5=30 6X6=36
7X1=7 7X2=14 7X3=21 7X4=28 7X5=35 7X6=42 7X7=49
8X1=8 8X2=16 8X3=24 8X4=32 8X5=40 8X6=48 8X7=56 8X8=64
9X1=9 9X2=18 9X3=27 9X4=36 9X5=45 9X6=54 9X7=63 9X8=72 9X9=81
标签:static oid print demo ati 乘法表 嵌套 out pre
原文地址:https://www.cnblogs.com/hzdwwzz/p/10513960.html