public class JavaDemo02{// 递归法求1到100的和
public static void main(String args[]){
System.out.println(sum(100));
}
public static int sum(int num)
{
if(num==1){
return 1;
}
return num+sum(num-1);
}
}
递归法求1+2+3+····+100public class JavaDemo02{// 递归法求1到100的和 public static void main(String args[]){ System.out.println(sum(100)); } public static int sum(int num) { ...