对于这一段代码我能够理解,压栈然后出栈就是6,5,4
package recursion;
public class testRecursion {
public static void main(String[] args) {
int num=3;
recursion(num);
}
private static void recursion(int n){
n++;
if(n<7){
recursion(n);
System.out.println(n);
}
}
}
但是对这段代码的输出很不理解
package recursion;
public class testRecursion {
public static void main(String[] args) {
int num=3;
recursion(num);
}
private static void recursion(int n){
n=n+1;
if(n<7){
recursion(n);
recursion(n);
System.out.println(n);
}
}
}
输出是:6 6 5 6 6 5 4