Java after class job-4

Source: Internet
Author: User

I. Write a method that uses the above algorithm to generate a random integer of a specified number (for example, 1000).

public class Suiji

{

private static final int N = 200;

private static final int left = 40;

private static final int right = 10000;

private static long x0 = 1L;

Private long a = 1103515245L;

Private long C = 12345L;

Private long m = 2147483648L;

Generate random numbers

Private Long rand (long R)

{

A,c,m is constant

R = (R * A + C)% m;//xn+1= (aXn + c) MoD m

return R;

}

Private long Little (int a, int b, long rand)

{

Return a + rand% (b-a + 1);

}

private void recursion (int count, long rand)

{

if (Count >= N)

{

Return

}

Rand = rand (RAND);

Long r = Little (left, right, Rand);

System.out.print (R + "");

Recursion (++count, Rand);

}

public static void Main (string[] args)

{

Suiji recur = new Suiji ();

Recur.recursion (0, x0);

}

}

Take a look at the following code, do you find anything special?

The code above shows the attributes of "method overloading" in Java, where different parameter types can automatically invoke the corresponding function (method), which is the overload of the method.

Two or more methods that meet the following conditions form an "overloaded" relationship:

(1) The method name is the same;

(2) The parameter types are different, the number of parameters is different, or the order of the parameter types is different.

Note: The return value of the method is not used as a criterion for method overloading.

Three. After-school homework: Using computer to calculate the number of combinations

After-school Assignment II:

Hanoi Tower Problem

After-school assignment three:

Use recursive method to determine whether a string is a palindrome

Java after class job-4

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.