动手动脑:编程一个方法利用以上算法生成指定数目的随机数

package suiji;//信1605-3 20163432

public class Suiji {
public long a=12345L;//定义long类型的a,b,c变量
public long c=12345L;
public long m=456123L;
public long r=1;
public long rand()//调用纯随机数发生器的函数
{
r=(r*a+c)%m;
return r;
}



 


public static void main(String[] args) {
// TODO Auto-generated method stub
Suiji s=new Suiji();
long r;
for(int i=1;i<1000;)//输出1000个随机数
{


r=s.rand();
System.out.print(r+" ");
i++;
if (i%20==0)//每输入20个换行
System.out.println("");

}
}

}

 

 

package methodOverload;//信1605-3 20163432 张运涛

//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)//int类型
{
return x * x;
}

public static double square(double y)//double类型
{
return y * y;
}
}

 

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

posted @ 2017-10-13 09:43  小张在搬砖  阅读(786)  评论(0编辑  收藏  举报