用Java语言的for循环写出五种99乘法表的不同输出样式
时间: 2023-11-27 15:53:40 浏览: 68
1. 普通输出样式:
```
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + (i*j) + "\t");
}
System.out.println();
}
```
2. 左对齐输出样式:
```
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.printf("%d*%d=%-2d ", j, i, j*i);
}
System.out.println();
}
```
3. 右对齐输出样式:
```
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.printf("%d*%d=%2d ", j, i, j*i);
}
System.out.println();
}
```
4. 竖式输出样式:
```
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.printf("%d*%d=%-2d ", j, i, j*i);
}
System.out.println();
}
```
5. 倒序输出样式:
```
for (int i = 9; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + (i*j) + "\t");
}
System.out.println();
}
```
阅读全文