java写出递归并完善
public class Test{
public static void main(String[] args){
System.out.println(method(5)); // 5 可以改成任何整数
}
public static int method(int n){
if n<=1 // 原代码为n==1 经改正应为 n<=1
return 1;
else
return n*method(n-1);
}
}
public class Test{
public static void main(String[] args){
System.out.println(method(5)); // 5 可以改成任何整数
}
public static int method(int n){
if n<=1 // 原代码为n==1 经改正应为 n<=1
return 1;
else
return n*method(n-1);
}
}