Java 递归 算法 递归求和 递归查询动态菜单

public class Test {  
    private int sum=0,num=1;  
    public int calSum(int maxnum){  
        if(num<=maxnum){  
            sum+=num;  
            num++;  
            calSum(maxnum);  
        }  
        return sum;  
    }  
    public static void main(String[] args) {  
        Test test=new Test();  
        System.out.println("1+2+3+...+100="+test.calSum(100));  
    }  
}  
    原文作者:递归算法
    原文地址: https://blog.csdn.net/simplemanMYB/article/details/79460721
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞