public static int sum(int n) {
int sum = n;
boolean isContinue = (n > 0) && (sum += sum(--n)) > 0;
return sum;
}
public static void main(String[] args) {
int result = sum(5);
System.out.println(result);
}
不使用循环条和件语句实现1+2+3+...n
最新推荐文章于 2024-02-25 16:44:22 发布