公式:java
公式的意思就是 x(n+1)=(16807*x(n))%2^31-1dom
代碼以下:函數
package javatask; import java.util.Random; import java.util.Scanner; public class Random1 { static Scanner in=new Scanner(System.in); static public void Seed(long seed) { Random rand=new Random(); long a,x=0,x1; System.out.println("請輸入想要產生的隨機數的個數"); a=in.nextLong(); for(long i=1;i<=a;i++) { x1=(16800*seed)%(Integer.MAX_VALUE); System.out.println(x1); x++; if(x<=(2e+32)-2) seed=x1; else seed=rand.nextLong(); } } public static void main(String []args) { long b; System.out.println("請輸入想要輸入的種子"); b=in.nextLong(); Seed(b); } }
1.知足如下兩個條件便可構成函數重載spa
①方法名相同3d
②參數類型不一樣,參數個數,參數類型的順序不一樣code
注意函數的返回值類型不能做爲函數重載的判斷條件:由於在運行時,一開始並不知道所調用的函數返回值是什麼,一開始只會根據參數的類型去尋找對應的函數blog
2.代碼:class
package javaclass2; // 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; } }
截圖:import