代码:
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);
}
}
运行结果: