题目描述

求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
 
 
题目链接:
 
 
 
关键点:
利用&&的短路特性,作为递归的结束条件。
 
 
public class Solution {
    public int Sum_Solution(int n) {
        int sum = n;
        boolean re = (n!=0&&(sum += Sum_Solution(n -1))>0);
        return sum;
    }
}

 

posted on 2020-06-09 22:24  MoonBeautiful  阅读(125)  评论(0编辑  收藏  举报