The third week of hands-on brain

The first is the use of pure random number generator to write a specified number of random integers generated, this program must first set up a seed x, and then into the algorithm.

Source:

package project1;

import java.util.Random;

import java.util.Scanner;

public class random1 {

static Scanner sc=new Scanner(System.in);

public static void main(String args[]){

Random rand =new Random();

. The System OUT .print ( "Please enter the generated random number");

int sum;

sum=sc.nextInt();

 

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

{

int x=rand.nextInt(100);

x=((16807*x+8)%(2^31-1));

        System.out.println(x);

}

}

}

 

The second method is to show java overloading. Function overloading need to meet the following conditions:

1. The method of the same name;

2. Different types of functions, a different number of arguments, or parameters of different types of sequence.

The return value is determined as the condition is not overloaded 3. The method of method.

And that program is in ppt different argument types,

Here is what I wrote a source code:

package project1;

 

public class use1 {

public void show(String name){

        System.out.println("姓名:"+name);

    }

    public void show(String name,int number){

        . System OUT .println ( "Name:" + name + "Student ID:" + number);

    }

}

 

Guess you like

Origin www.cnblogs.com/ljpljm/p/11599896.html