希望可以帮到你!
public class SUM{public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("请输入n: ");
int n=s.nextInt();
int sum = sdg(n); System.out.println(sum);
}
static int sdg(int x){
if(x==1){return 1;}
else{return x+sdg(x-1);
}
}