public class InfiniteRecursion1 // demonstration of recursion without a base case, causes infinite recursion { // in actuality it causes a StackOverflowException because we run out of Stack space // or an ArithmeticException because we overflow the int parameter x, whichever comes first // (StackOverflow will most likely occur first) public static void main(String[] args) { System.out.println(infinity(20)); // invoke recursive function with some positive value for x, the value is immaterial } public static int infinity(int x) { return x + infinity(x-1); // oops, no base case } }