动手动脑一:public class suijishu { private static final int N = 200; private static final int LEFT = 40; private static final int RIGHT = 10000; private static long x0 = 1L; private long a = 1103515245L; private long c = 12345L; private long m = 2147483648L; private long rand ( long r ) { r = ( r * a + c ) % m;//Xn+1=(aXn + c)mod m return r; } private long little ( int a, int b, long rand ) { return a + rand % ( b - a + 1 ); } private void recursion ( int count, long rand ) { if (count >= N) { return; } rand = rand (rand); long r = little (LEFT, RIGHT, rand); System.out.print (r + " "); recursion (++count, rand); } public static void main ( String[] args ) { suijishu re = new suijishu (); re.recursion (0, x0); } }
动手动脑二:
我发现同样名称的函数可以不同,这使得函数变得更全面,不同的参数类型可以自动调用相应的函数,即方法的重载。
满足以下条件的两个或多个方法构成“重载”关系:
(1)方法名相同;
(2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。
原文地址:https://www.cnblogs.com/yuanxiaochou/p/9788703.html
时间: 2024-10-17 10:32:56