动手动脑02

(1)随机数生成器:
package test2;
/*
 * 产生指定书目的随机整数
 */
public class RandomTest {
 public static final int MAX=100; //MAX相当于常量
 public long a=12345L;
 public long c=12345L;
 public long m=12365L;
 public long x=1;
 //随机数生成器
 public long rand() {
  x=(x*a+c)%m;
  return x;
 }
 public static void main(String []args) {
  
  RandomTest s=new RandomTest();
  long r;
  for(int i=0;i<MAX;) {
   r=s.rand();
   System.out.print(r+" ");
   i++;
   if(i%10==0)
    System.out.println();
  }
  
 }
}

  实验截图:

(2)

java允许在同一范围中声明几个功能类似的同名函数,但这些同名函数的形式参数(参数的个数,类型或顺序)必须不同,称之为函数的重载。

 (3)

该方法参数表中可以输出各种类型,对其进行输出。

猜你喜欢

转载自www.cnblogs.com/Excusezuo/p/9787111.html