Overloading and recursive summary exercises

Overloaded methods
sometimes we need to be compatible with a variety of parameters of a function, we can use the method overloading.
Here Insert Picture Description
Name of the method call but add some add int sum is calculated, some double sum.; the same method name, offer different versions of the implementation, called method overloading
overloading rules: the same method name, parameters of different methods (the number of parameters or parameter type), the return value type does not affect the method of overloading.
recursive
recursive concept: a method call during execution itself, called "recursive".
recursive corresponds to the "mathematical induction" in mathematics, has a start condition, then there is a recurrence formula
1. recursion, N factorial
Here Insert Picture Description

2. recursion 1 + 2 + 3 + ... + 10
Here Insert Picture Description
3. print a sequence number each bit (e.g. 1234 1 234 prints out)
Here Insert Picture Description
4. Write a recursive method, enter a non-negative integer, it returns composition the sum of the numbers.

Here Insert Picture Description
Note: Some problem to solve is to use natural (eg Fibonacci number, binary, etc.), this time using a recursive recursively defined easily.
Some question the use of non-recursive and recursive (cycle) can be resolved. At this point it is recommended to use more cycles, compared to the recursive, non-recursive program more efficient ..
The N-th recursion Fibonacci number (multiple repetitions)

Here Insert Picture Description

Published 60 original articles · won praise 23 · views 3329

Guess you like

Origin blog.csdn.net/weixin_44945537/article/details/101108286