September 23 Workshop

First, the hands-on brain 1

Title: Full "hand code for" random number generator

 

 Source Code:

package test3;

import java.util.Random;
import java.util.Scanner;

{class Crandom public
public static void main (String [] args) {
System.out.println ( "Please enter the number you want to generate a random number:");
Scanner Scanner Scanner new new = (the System.in);
int n- scanner.nextInt = ();
the random random new new = the random ();
int SEED = random.nextInt (100); // less than 100 generates a random number
for (int I = 0; I <n-; I ++)
{
SEED = ( 7 ^ 5 * seed)% 2147483647 ; // apply mathematical formula
System.out.println (seed); // output of each random number
}

}
}

test:

 

 Hands-on brain 2:

Title: Consider the following code, you find what is special about it?

public class MethodOverload {
    public static void main(String[] args) {
        System.out.println("The square of integer 7 is " + square(7));
        System.out.println("\nThe square of double 7.5 is " + square(7.5));
    }

    public static int square(int x) {
        return x * x;
    }

    public static double square(doubley) {
         return y * y; 
    } 
}

in conclusion:

1, this program function overloading, the same function name, the function of different parameter types.

2, the use of function overloading may reduce the number of function names, function to increase readability

Two or more methods ********** configuration satisfies the following conditions "reload" the relationship:

Same as (1) a method name; product (2) different types of parameters, number of different parameters, different parameters or the type of order.

Note: Returns the value of the determination condition as a method of method overloading.

Second, after-school practice

1, look at the JDK System.out.println () method, what have you found?

1, System java.lang class is a package, in the Object class inheritance.

2, in the System category, out is a static member variables PrintStream class, so you can use the class name. Variable names referenced. (API Display: out is a "standard" output stream This stream is already open and ready to accept the output data Typically this stream corresponds to display output or other specified by the host environment or user output destination...)

3, println () is a method of PrintStream was out call.

4, println () is a method, there are different types of parameters, the parameters will be passed when performing the output.

 

Guess you like

Origin www.cnblogs.com/a155-/p/11586029.html