一。随机数
public class Suiji {
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 little1 ( 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 = little1 (LEFT, RIGHT, rand);
System.out.print (r + " ");
recursion (++count, rand);
}
private long little(int left2, int right2, long rand)
{
// TODO Auto-generated method stub
return 0;
}
public static void main ( String[] args ){
Suiji recur = new Suiji ();
recur.recursion (0, x0);
}
}
实验结果;
二方法重载:
public class Chongzai {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("The square of integer 10 is " + square(7));
System.out.println("
The square of double 3.2 is " + square(7.5));
}
public static int square(int x)
{
return x*x;
}
public static double square(double y)
{
return y*y;
}
}
满足以下条件的两个或多个方法构成“重载”关系:
(1)方法名相同;
(2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。
注意:方法的返回值不作为方法重载的判断条件。