用java写个九九乘法表
时间: 2023-09-12 08:05:19 浏览: 89
### 回答1:
好的,这是一个使用 Java 编写的九九乘法表的示例代码:
```
public class MultiplicationTable {
public static void main(String[] args) {
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();
}
}
}
```
在这个代码中,我们使用了两个 for 循环,第一个循环控制行数,第二个循环控制列数。我们在内部循环中计算乘积,并使用 System.out.print() 方法打印到控制台。最后,使用 System.out.println() 换行。
### 回答2:
下面是使用Java编写的九九乘法表:
```java
public class MultiplicationTable {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " × " + i + " = " + (j * i) + " ");
}
System.out.println();
}
}
}
```
上述代码中,使用了两个嵌套的for循环来输出九九乘法表。外层循环控制乘法表的行数,内层循环控制每一行的列数。
在外层循环中,循环变量i从1逐渐增加到9,表示当前的行数。在内层循环中,循环变量j从1逐渐增加到i,表示当前的列数。每次循环会打印出某一行的乘法表达式,并换行。
运行上述代码,即可输出如下的九九乘法表:
```
1 × 1 = 1
1 × 2 = 2 2 × 2 = 4
1 × 3 = 3 2 × 3 = 6 3 × 3 = 9
1 × 4 = 4 2 × 4 = 8 3 × 4 = 12 4 × 4 = 16
1 × 5 = 5 2 × 5 = 10 3 × 5 = 15 4 × 5 = 20 5 × 5 = 25
1 × 6 = 6 2 × 6 = 12 3 × 6 = 18 4 × 6 = 24 5 × 6 = 30 6 × 6 = 36
1 × 7 = 7 2 × 7 = 14 3 × 7 = 21 4 × 7 = 28 5 × 7 = 35 6 × 7 = 42 7 × 7 = 49
1 × 8 = 8 2 × 8 = 16 3 × 8 = 24 4 × 8 = 32 5 × 8 = 40 6 × 8 = 48 7 × 8 = 56 8 × 8 = 64
1 × 9 = 9 2 × 9 = 18 3 × 9 = 27 4 × 9 = 36 5 × 9 = 45 6 × 9 = 54 7 × 9 = 63 8 × 9 = 72 9 × 9 = 81
```
以上就是使用Java编写的九九乘法表的代码和输出结果。
### 回答3:
九九乘法表是一种常见的数学题型,可以用Java编写一个简单的九九乘法表程序来实现。下面是一个示例程序:
```java
public class MultiplicationTable {
public static void main(String[] args) {
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();
}
}
}
```
上述代码中,我们使用了两个嵌套的for循环,外层循环控制乘法表的行数,内层循环控制每一行的内容。在每一行中,内层循环输出了`j × i = (i * j)`的表达式,并使用制表符`\t`进行分隔。
运行上述代码,即可输出九九乘法表的结果。其中的九九乘法表如下:
1 × 1 = 1
1 × 2 = 2 2 × 2 = 4
1 × 3 = 3 2 × 3 = 6 3 × 3 = 9
1 × 4 = 4 2 × 4 = 8 3 × 4 = 12 4 × 4 = 16
1 × 5 = 5 2 × 5 = 10 3 × 5 = 15 4 × 5 = 20 5 × 5 = 25
1 × 6 = 6 2 × 6 = 12 3 × 6 = 18 4 × 6 = 24 5 × 6 = 30 6 × 6 = 36
1 × 7 = 7 2 × 7 = 14 3 × 7 = 21 4 × 7 = 28 5 × 7 = 35 6 × 7 = 42 7 × 7 = 49
1 × 8 = 8 2 × 8 = 16 3 × 8 = 24 4 × 8 = 32 5 × 8 = 40 6 × 8 = 48 7 × 8 = 56 8 × 8 = 64
1 × 9 = 9 2 × 9 = 18 3 × 9 = 27 4 × 9 = 36 5 × 9 = 45 6 × 9 = 54 7 × 9 = 63 8 × 9 = 72 9 × 9 = 81
这样,我们就用Java编写了一个简单的九九乘法表程序。
阅读全文