public class InfiniteRecursion2 // demonstration of recursion with a faulty base case that leads to infinite recursion { // (StackOverflow or ArithmeticException) 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) { if(x<=0) return 0; // base case is unreachable if we call infinity with x>0 else return x + infinity(x+1); // because we are incrementing x each time, not decrementing it } }