`
chengjie177
  • 浏览: 25849 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
文章分类
社区版块
存档分类
最新评论

简单的递归

阅读更多
int result = 0;

    /**
     * 递归求n+(n-1)+(n-2)+...+1的和
     * @param n
     * @return
     */
    public int recursion(int n) {
        if( n > 0 ) {
            result = result + n;
            recursion(n - 1);
        }
        return result;
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics