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