Applets for Java recursive and recursive applications

Source: Internet
Author: User

1. Method overloading

Different types of return values are obtained by calling different functions:


Overloads of the method:
* Method name is the same
* Depending on the parameter type, the parameter type Order, the number of parameters to determine the criteria to distinguish calls
* Return value is not used as a judging condition

2. Yang Hui Triangle code:

The output of the Yang Hui Triangle is completed by a recursive relationship.

3. The judgment of palindrome string:

Code:

By using the recursive relationship, the process of judging whether a palindrome is done by invoking the function of itself.

4. Generate random numbers of code:

for (Long i = 1; i <=; i++) {//1000 random numbers
Value = 1 + (int) (Math.random () * 100); The range of random numbers is 1~100

if (i&50==0) output+= "\ n"; 50 numbers per line

5. Calculate the number of combinations:

(1) Calculation using the formula of combination number:

Use the combination number formula to calculate with n!

(2) Using recursive relations to calculate:


6. Hanoi Game:

(1) Code:

I

(2) Code:

Applets for Java recursive and recursive applications

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.