/*
自然数之和 函数重载
*/
import java.util.Scanner;
class Demo2
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int x=scanner.nextInt();
int result=get(x);
System.out.println(result);
}
public static int get(int x){
if(x==1){
return 1;
} else {
int temp=0;
temp=get(x-1);
return temp+x;
}
}
} |
|