JZ47 求1+2+3+...+n

题目描述

求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 bool = (n > 1) && ((sum += Sum_Solution(n-1)) > 0);
        return sum;
    }
}

在这里插入图片描述

posted @ 2022-05-14 20:07  长勺  阅读(15)  评论(0)    收藏  举报