//打印乘法表
//双重循环打印,单循环打印,递归
class MultiTable {
public static void main(String[] args){
test1(9);
test2(9);
test3(1);
}
//双重循环打印. 这是最多见的作法。
public static void test1(int n){
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
//单循环打印
public static void test2(int n){
for(int row=1,col=1; row<n ;col++){
System.out.print(col+"*"+row+"="+col*row+"\t");
if(row==col){
System.out.println();
col = 0;
row++;
}
}
递归
}
//递归
public static void test3(int row){
for(int i=1; i<=row ;i++){
System.out.print(i+"*"+row+"="+i*row+"\t");
}
if(row<9){
System.out.println();
test3(++row);
} class
}
} test