如何用Java语言编写乘法口诀表?
public class Demo01 {
public static void main(String[] args){
Demo01MultiplicationTable();
}
//乘法口诀表的方法:
public static void Demo01MultiplicationTable(){
int i=1,j=1;
// 乘法口诀正三角
for (i = 1; i <= 9; i++) {
for (j = 1; j <= i; j++) {
System.out.print(j+"*"+i+"="+i*j+" ");
}
System.out.println();
}
System.out.println("========================");
// 乘法口诀表倒三角
for (i = 9; i >= 1; i--) {
for (j = 1; j <= i; j++) {
System.out.print(j+"*"+i+"="+i*j+" ");
}
System.out.println();
}
}
}
执行结果如下:
守着安静的沙漠,等待着花开...