使用两个循环打印9*9乘法表是最简单的,只使用一个循环的话难度增长一点,一个循环都不使用的话,也能够作到。算法
个人方法是递归:总共使用了三个方法,两次递归。 使用递归来打印9*9乘法表,好像有一点小题大作了,我认为它的意义在于锻炼一下本身的算法吧,闲着无事对编程语言小小的消遣。 编程
代码并不复杂,注释就不写了,直接贴代码:编程语言
public class UpGreat { public static void main(String args[]) { fun1(9, 1); } public static void fun1(int max, int start) { if (start == max) { fun2(start, 1); return; } fun2(start, 1); start++; System.out.println(); fun1(max, start); } public static void fun2(int first, int second) { if (first == second) { fun3(first, second); return; } fun3(first, second); second++; fun2(first, second); } public static void fun3(int i, int j) { System.out.print(i + "*" + j + "=" + i * j + "\t"); return; } }
若是你有其余的解决办法,欢迎交流!code