lihongjie0209
2018-03-20 11:34:26 +08:00
```
public class test {
public static void main(String[] args) {
long sum = sum(1, 100000);
System.out.println(sum);
}
public static long sum(int start, int end) {
System.out.println("sum is called!!");
if (start == end) {
return start;
}else{
return sum(start, end - 1) + end;
}
}
}
sum is called!!
sum is called!!
sum is called!!
Exception in thread "main" java.lang.StackOverflowError
at java.io.PrintStream.write(PrintStream.java:526)
at java.io.PrintStream.print(PrintStream.java:669)
at java.io.PrintStream.println(PrintStream.java:806)
at test.sum(test.java:12)
at test.sum(test.java:18)
at test.sum(test.java:18)
```