import java.util.Scanner; public class Demo10 { 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*(n + 1)/2 + 1 = " + (n*(n+1)/2 + 1) ); // System.out.println("n*(n + 1)/2 + 1 = " + n*(n+1)/2 + 1); BUG // ^^ concatenate 1 } public static void recurse(int n) { if ( n == 0 ) { c++; // Simulate doPrimitive by // keep track of # doPrimitive() executed return; } else { for ( int i = 0; i < n; i++ ) c++; // Keep track of # doPrimitive() executed recurse(n - 1); } } }