using java Recursion Create a Class to practice with Recursi
using java
(Recursion) Create a Class to practice with Recursion. Call your class “Recur”, and store it in a file called “Recur.java”. In this class include just one method call it methRecur(). Have main start things out by instantiating the class and calling the methRecur() method. In the methRecur() method, first print out “Entering Method”. Then call the methRecur() method again. After calling the method print “Leaving Method”. Make it so that the method will only recurse 100 times. Use an if statement for this.
Solution
Recur.java
public class Recur {
public static void main(String[] args) {
methRecur(100);
}
public static void methRecur(int n){
if(n==0){
return;
}
System.out.println(\"Entering Method\");
methRecur(n-1);
System.out.println(\"Leaving Method\");
}
}
Output:
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Entering Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method
Leaving Method



