[劍指offer] JAVA版題解 面試題64

在這裏插入圖片描述

代碼演示:

package swordfingeroffer;

/**
 * <p>Description: </p>
 *
 * @author 羅志遠
 * @version 1.0
 * @name InterviewQuestion64
 * @date 2020-07-05 17:57
 */
public class InterviewQuestion64 {
    public int sumFromOneToN(int n) {
        int sum = n;
        boolean b = (n > 0) && ((sum += sumFromOneToN(n - 1)) > 0);
        return sum;
    }

    public static void main(String[] args) {
        InterviewQuestion64 interviewQuestion64 = new InterviewQuestion64();
        System.out.println(interviewQuestion64.sumFromOneToN(5));
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章