Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help my homework.. I have a Java source below. class RecursiveMethods { RecursiveMethods() // default constructor { } public int fOf(int x) { if
Please help my homework..
I have a Java source below.
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; // recursive call } } } 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(); // Call fOf with an x value of 20 x = 20; System.out.println("Example 1: x = " + x); System.out.println("f(" + x + ") = " + rMethods.fOf(x)); System.out.println(); // Call fOf with an x value of 19 x = 19; System.out.println("Example 2: x = " + x); System.out.println("f(" + x + ") = " + rMethods.fOf(x)); System.out.println(); // Call fOf with an x value of 18 x = 18; System.out.println("Example 3: x = " + x); System.out.println("f(" + x + ") = " + rMethods.fOf(x)); System.out.println(rMethods.fOf(x)); System.out.println(); } }
Q1. Determine the value for the following recursive method when x = 18
-5 7 -2 2 -3
Q2. Determine the value for the following recursive method when x = 19
9 4 -5 -4 2
Q3. Determine the value for the following recursive method when x = -100
-7 14 -50 3 -2
Q4. Determine the value for the following recursive method when x = 7
7 -13 8 4 -2
Q5. Determine the value for the following recursive method when x = 35
9 35 -6 4 -12
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started