java使用普通算法实现99乘法表,使用递归实现99乘法表

时间:2024-01-21 13:09:51

public class recursionTest {
public static void main(String[] args) {
//jiujiu();
m(9);
}
/*
* for循环99乘法表
* */
public static void jiujiu(){
for (int i = 1; i < 10; i++) {
for (int j = 1; j <= i; j++) {
System.out.println(j + "*" + i + "=" + j * i+" ");
}
System.out.println(" ");
}
}
/*
* 递归99乘法表
*
* */
public static void m(int i){
if(i==1){
System.out.println("1*1=1");
}else{
m(i-1);
for(int j=1;j<=i;j++){
System.out.println(j + "*" + i + "=" + j * i+" ");
}
System.out.println(" ");
}
}
}