import java.util.Scanner;
class DG
{
public int count(int n){
if(n==1)
return 1;
else
return count(n-1)+n;
}
}
public class Test
{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
DG dg = new DG();
System.out.print("请输入一个数:");
int n =sc.nextInt();
System.out.println(dg.count(n));
}
}
来源:oschina
链接:https://my.oschina.net/u/988276/blog/117581