java 递归调用
在java中使用递归调用必须使用if分支语句吗? 为什么不用就报错,用了就好?(新人,求前辈解答)
public static void main(String[] args){
int sun=0;
sun = fun(100);
System.out.println(sun);
}
public static int fun(int temp){
if(temp==1){
return 1;
}else
return temp+fun(temp-1);
}
能运行
public static void main(String[] args){
int sun=0;
sun = fun(100);
System.out.println(sun);
}
public static int fun(int temp){
return temp+fun(temp-1);
}
这样就不行了