递归求1-100相加之和

递归求1-100相加之和

public class Recursion {

    public static int SumAll(int MAX_NUMBER){
        if (MAX_NUMBER == 1){
            return 1;
        }else{
            return MAX_NUMBER + SumAll(MAX_NUMBER-1);
        }
    }

    
    public static void main(String[] args) {
        System.out.println(SumAll(100));
    }
}
posted @ 2020-11-26 17:02  ED1S0N  阅读(126)  评论(0编辑  收藏  举报