public class Test {
public static int sum(int a){
if(a==1){
return 1;
}
return sum(a-1)+a;
}
public static void main(String[] args) {
System.out.println(sum(100));
}
}
public class Test {
public static int sum(int a){
if(a==1){
return 1;
}
return sum(a-1)+a;
}
public static void main(String[] args) {
System.out.println(sum(100));
}
}
本文标题:1+到n输入,总和输出,递归实现
本文链接:https://www.haomeiwen.com/subject/rkwgxctx.html
网友评论