Recur.java
// Recur.java - Recursive Goodbyepublic Class Recur {Public Static Void Main (STRING [] args) {SaygoodbyE (5);} static void sygoodbye (int n) {if (n <1) // base case system.out. Println ("########"); else {system.out.println ("Say Goodbye Gracie."); SayGoodbye (N - 1); // Recursion}}}
The recursive method is to transform the problem into a smaller problem, for example, to count the steps of a number N, as long as the N-multiply ((N-1) steps), and the step of (N-1) can continue to decompose Until 1, at this time, the result value can be directly obtained, then return, calculate the data of the previous layer, and finally the step of N. Generally simple recursive methods can be rewritten with iteration, and for a particular input value, iterative method only calls once, and the recursive method is called N times, and the method call is large, so iterative version is usually more efficient than recursive methods.