java--Recursive invocation

Source: Internet
Author: User

The recursive function calls itself, and through its own corresponding parameters, this calculation is performed during the layer until certain conditions are met, as long as the call is stopped.

Characteristics of Recursive functions

1. function to invoke itself directly or indirectly.

2. To have a recursive termination condition check. That is, after the condition of the recursive termination is satisfied. The self function is no longer called.

3. If the condition of recursive termination is not satisfied, the invocation of an expression involving a recursive call . When the function itself is called, the number of parameters about the terminating condition is changed and the direction of the recursive termination needs to be changed.

Example:

Calculate the factorial of 5?

public class Testwudejiecheng{public static void Main (String arg[]) {System.out.println (F (5));} recursive function public static int f (int n) {if (n==1)//Termination condition {return 1;} Else{return n*f (n-1);}}

from the above example, we can further see the characteristics of recursive calls, call their own functions, there are termination conditions. At the same time, it can be seen from the example of the recursive algorithm's strengths structure clear. Readability is strong, and easy uses mathematical induction in order to prove the correctness of the algorithm, so it is designed algorithm, debugger will bring a very generous.

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

java--Recursive invocation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.