打印九九乘法表java
时间: 2023-11-04 10:58:27 浏览: 90
以下是用Java打印九九乘法表的源代码:
```java
for(int i=1; i<=9; i++) {
for(int j=1; j<=i; j++) {
System.out.print(i + " * " + j + " = " + i*j + " ");
}
System.out.println();
}
```
此代码将打印出九九乘法表,每一行表示一个乘法表达式,例如"1 * 1 = 1"。
相关问题
打印九九乘法表 java
Sure! Here's how you can print the multiplication table using Java:
```java
public class MultiplicationTable {
public static void main(String[] args) {
int size = 9;
for (int i = 1; i <= size; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " * " + i + " = " + (i * j) + " ");
}
System.out.println();
}
}
}
```
This code will print the multiplication table from 1 to 9. Each line represents a number, and the numbers in each line are multiplied with the numbers in the column.
打印九九乘法表Java完整代码
当然,下面是一个打印九九乘法表的Java完整代码:
```java
public class MultiplicationTable {
public static void main(String[] args) {
int size = 9; // 乘法表的大小
// 打印九九乘法表
for (int i = 1; i <= size; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " * " + i + " = " + (i * j) + "\t");
}
System.out.println();
}
}
}
```
这段代码使用了两个嵌套的循环来打印九九乘法表。外层循环控制行数,内层循环控制每行的列数。通过计算两个循环变量的乘积来得到每个乘法表达式的结果,并将其打印出来。
阅读全文