java编程,1+2+3……+n,怎么弄,像昨天那样

如题所述

int f(int n){
if(n==0){
return n;
}else if(n>0){
return f(n-1)+n;
}else{
throw new IllegalArgumentException("n 不能为负");
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜