如何用idea打印九九乘法表
九九乘法表如图
1. 我们先打印第一列,
2. 我们把固定的一个1再用一个循环包起来,
3. 去掉重复项,i<=j,
4. 最后就调整样式,
代码如下
- 先写这行代码
public static void main(String[] args) {
for(int i = 1;i<=9;i++){
System.out.println(1+"*"+i+"="+(1*i));
}
}
}
运行结果下图
如下图:
2. 我们把一行写下来了再给上面套一个for循环
public static void main(String[] args) {
for(int j = 1;j<=9;j++){
for(int i = 1;i<=j;i++){
System.out.print(i+"*"+j+"="+(j*i)+"\t");
}
System.out.println();
}
}
}
- 运行完成后结果如下图就完成了
学自b站狂神说java