zoukankan      html  css  js  c++  java
  • 01作业

    动手动脑
    1,使用纯随机数发生器:Xn+1=(aXn+c) mod Integer.MAX_VALUE
    编写一个方法,生成指定数目的随机整数。

    查阅相关资料知道了,需要确定种子,也就是X0的初值,
    然后用for语句调用一下即可。
    为了方便,20十个随机数一行。

    源代码:

    public class test0 {


    public static void main(String[] args) {
    // TODO Auto-generated method stub
    long seed = System.currentTimeMillis();//种子
    long random=(16807 * seed) % Integer.MAX_VALUE;
    int i,count=0;
    for(i=1;i<=1000;i++)
    {
    random=(16807 * random) % Integer.MAX_VALUE;
    System.out.print(random+" ");
    count++;
    if(count%20==0)//为了方便20个一换行
    System.out.println();
    }
    }

    }

    运行截图:略。


    2.查看一下jdk中的System.out.println()方法,你发现了什么?

    System.out.println()运用了函数重载的方法,是参数不同,函数名相同的函数重载的标准案例,根据用户所给的参数的不同,自动调用不用的函数来实现功能,

    避免了函数名过多的麻烦,直接运用即可。

  • 相关阅读:
    [BZOJ3172]单词
    [BZOJ2434]阿狸的打字机
    [BZOJ1195]最短母串
    [codeforces743E]Vladik and cards
    [BZOJ2553]禁忌
    [BZOJ1009]GT考试
    [BZOJ3507]通配符匹配
    [BZOJ4027]兔子与樱花
    test20190308
    Luogu P2742 模板-二维凸包
  • 原文地址:https://www.cnblogs.com/shenaoyu/p/11585966.html
Copyright © 2011-2022 走看看