import java.util.Arrays; public class Test2_P3_31 { private static int depth; public static void main(String[] args) { int[] ary = new int[] {-5, 1, -3, 4, 8, -9, 6}; depth = -1; blorp(ary, ary.length); } public static int blorp(int[] a, int n) { depth++; String message = "Received a: " + Arrays.toString(a) + "; n: " + n; printMessage(message); int result; if (n == 0) { result = 0; } else if (a[n-1] < 0) { a[n-1] = 0; result = blorp(a, n-1) + 1; } else { result = blorp(a, n-1); } printMessage("Having " + message + ", now returning " + result); depth--; return result; } /* Prints the specified string, preceded by a number of spaces ** proportional to the value of 'depth'. Then skips to next line. */ private static void printMessage(String s) { printSpaces(2*depth); System.out.println(s); } /* Prints the specified number of spaces. ** pre: k >= 0 */ private static void printSpaces(int k) { for (int i=0; i != k; i++) { System.out.print(' '); } } }