java for循环乘法表
时间: 2023-08-21 18:10:53 浏览: 121
java代码-使用java循环嵌套九九乘法表的源代码
以下是使用Java的嵌套for循环打印乘法表的两种方法:
方法一:
```java
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + (j * i) + "\t");
}
System.out.println();
}
```
方法二:
```java
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (j <= i) {
System.out.print(j + "*" + i + "=" + (i * j) + "\t");
}
if (j == 9) {
System.out.println();
}
}
}
```
这两种方法的区别在于第二个嵌套的for循环的条件判断和插入换行的时机。方法一的第二个for循环语句在j=i的时候就判断运行最后一次循环,然后在此循环结束时插入换行。方法二的第二个for循环语句会一直循环到j=9,在j=9时插入换行再退出循环。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* *3* [Java用for循环打印九九乘法表](https://blog.csdn.net/Palpitate233/article/details/129779081)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [使用Java的for循环编写九九乘法表](https://blog.csdn.net/qq_46096136/article/details/125953129)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文