Could someone help me understand this code? Thanks
So the program will print out
"Example 1: x = 20
20 > 10, therefore ... f(20) = f(20 - 3) + 2 = f(17) + 2
17 > 10, therefore ... f(17) = f(17 - 3) + 2 = f(14) + 2
14 > 10, therefore ... f(14) = f(14 - 3) + 2 = f(11) + 2
11 > 10, therefore ... f(11) = f(11 - 3) + 2 = f(8) + 2
8 <= 10, therefore ... f(8) = -5
f(20) = 3
"
How does the computer know to take -5 and + by 8? Thanks
class RecursiveMethods { RecursiveMethods() //default constructor { } public int fOf(int x) { if (x <= 10) //the base case { System.out.println(x + " <= 10, therefore ... f(" + x + ") = -5"); return -5; } else { System.out.println(x + " > 10, therefore ... f(" + x + ") = f(" + x + " - 3) + 2 = f(" + (x -3) + ") + 2"); return fOf(x-3) + 2; } } } public class RecursionMethodTester { public static void main(String[] args) { int x; RecursiveMethods rMethods = new RecursiveMethods(); System.out.println("---------------------------------"); System.out.println(" f(x - 3) + 2 if x > 10"); System.out.println("f(x) = "); System.out.println(" -5 if x <= 10"); System.out.println("---------------------------------"); System.out.println(); x = 20; System.out.println("Example 1: x = " + x); System.out.println("f(" + x + ") = " + rMethods.fOf(x)); System.out.println();