import java.util.Scanner; public class Demo9 { public static int c = 0; // Counts # recursive method has been called public static void main(String[] argv) { Scanner in = new Scanner(System.in); System.out.print("Enter n = "); int n = in.nextInt(); recurse(n); System.out.println("Runtime complexity = " + c); System.out.println("n + 1 = " + (n+1)); } public static int recurse(int n) { if ( n == 0 ) { c++; // Simulate doPrimitive by // keep track of # doPrimitive() executed return 1; } else { c++; // Keep track of # doPrimitive() executed return 1 + recurse(n - 1); } } }