用递归计算1-100所有自然数的和
作者:互联网
package com.atguigu.exer; public class RecursionTest { public static void main(String[] args){ Recursion recur = new Recursion(); System.out.println(recur.getSum(100)); } } class Recursion{ public int getSum(int n){ if(n == 1){ return 1; }else{ return n + getSum(n - 1); } } }
标签:return,recur,int,Recursion,自然数,getSum,递归计算,100,public 来源: https://www.cnblogs.com/yzyjava/p/14377056.html