4.7(1)——输出九九乘法表

来源:互联网 发布:js插件编写 编辑:程序博客网 时间:2024/06/04 19:34

代码:

public class 九九乘法表 {

public static void main(String[] args) {
StringBuffer result = new StringBuffer();
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
result.append(i).append(" * ").append(j).append(" = ").append(i * j);
if (j < i) {
result.append(" , ");
}
}
if (i < 9) {
result.append("\r\n");
}
}
System.out.print(result);
}

}

运行结果: