java面向对象实现九九乘法表
时间: 2024-06-13 11:04:51 浏览: 81
下面是使用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 + "x" + i + "=" + i * j + "\t");
}
System.out.println();
}
}
}
```
这段代码中,我们定义了一个名为MultiplicationTable的类,其中包含了一个名为main的静态方法。在main方法中,我们使用两个for循环来实现九九乘法表的输出。外层循环控制行数,内层循环控制列数。在内层循环中,我们使用System.out.print方法来输出每个乘法表达式,使用"\t"来实现对齐。最后,在内层循环结束后,我们使用System.out.println方法来换行。
阅读全文
相关推荐















