Question: /* name class description define factorial */ public class RecursionBasics { public static void main(String[] args) { //recursiveMethod(0); //printNumbersIterative(); //printNumbersRecursive(0); //System.out.println(Factorial of 4 is:

/* name class description define factorial */
public class RecursionBasics {
public static void main(String[] args) { //recursiveMethod(0); //printNumbersIterative(); //printNumbersRecursive(0); //System.out.println("Factorial of 4 is: " + factorial(4)); System.out.println("Factorial of 4 is: " + factorialR(4, 1)); }
private static void recursiveMethod(int n) { if { calling recursiveMethod(n +1) print....("Recursive method called, n is: " + n); } else print....("Base/terminal case reached, no more recursive calls!"); } private static void printNumbersIterative(){ while { .......print...(i); ......; //increment i++ } } private static void printNumbersRecursive(int i){ if { //base case ......(i); ......(i+1); } } private static int factorial(int n){ int fact = 1; for....... return ......... } private static int factorialR(int n, int i) { if ..... } else return ......; }
}
(Write in JAVA**)
Specifications for # 2 output (each students output may differ: PROVIDE OUTPUT RUNNING EACH (5) METHOD- (when methods are called be sure to print out which method you are using). recursiveMethod, printNumbersIterative, printNumbersRecursive, factorial, factorialR. 5 points for each method run with output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
