
2个回答
展开全部
public class Test1 {
public static void main(String[] args) {
// 循环
int n = 5;
int mul1 = 1;
for (int i = 1; i <= n; i++) {
mul1 = mul1 * i;
}
System.out.println(mul1);
// 递归
int mul2 = 1;
mul2 = Test1.test(n);
System.out.println(mul2);
}
public static int test(int n) {
if (n == 1) {
return n;
} else {
return test(n - 1) *n;
}
}
}
public static void main(String[] args) {
// 循环
int n = 5;
int mul1 = 1;
for (int i = 1; i <= n; i++) {
mul1 = mul1 * i;
}
System.out.println(mul1);
// 递归
int mul2 = 1;
mul2 = Test1.test(n);
System.out.println(mul2);
}
public static int test(int n) {
if (n == 1) {
return n;
} else {
return test(n - 1) *n;
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询