20190925Java class record (b)

1. random test

public class test2{
    public static void main(String[] args) {
        int[] n=new int [1001];
        n[0]=1;
        for(int i=0;i<1000;++i){
            n[i+1]=(16807*n[i]+0)%2147483647;
            System.out.println(n[i]);
        }
        }
    }
    

2. MethodOverload

// MethodOverload.java
// Using overloaded methods

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(double y) {
        return y *Y; 
    } 
}

Code shows the above-described exemplary Java "Method overloads (overload)" characteristic.

Two or more of the following methods constituting condition "Overload" Relationship: same as (1) a method name; product (2) different types of parameters, number of different parameters, the parameters or the order of different type.

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

Guess you like

Origin www.cnblogs.com/deepend/p/11599768.html