Java Classroom questions and Answers 2

Source: Internet
Author: User

Question One

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

Answer: xn+1= (7^5*XN) mod (2^31-1)

Program source code :

import java.util.Random;

import Java.util.Scanner;

Public class Randomcount

{

Public Static void Main (string[] args)

{

Random rand=new random ();

System. out. Print (" Please enter the number of random numbers you want to output:");

Scanner in =new Scanner (System. in);

int n,x;

N=in.nextint ();

X=rand.nextint (100);

for (int i=0;i<n;i++)

{

x= (7^5*x+0)%2147483647;

System. out. Print (x+ "");

if (i% 10 = = 0)

System. out. println ();

}

}

Results:

Question Two

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

A: This is called method overloading, for method overloads, parameter names must be the same, parameter types can be different, the number of parameters can be different, and the order of parameter types can be different. But the return value instinct as the judging condition.

Question Three

Take a look System.out.println () method in JDK , what did you find?

A: There are many functions in System.out.println (), but the method names are print (). Overloads of the method are used.

Java Classroom questions and Answers 2

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.