错与对并不是绝对的

Java课程02-动手动脑

1、编写一个方法,生成一千个随机数,纯随机数发生器。

package random;

public class random {

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

}

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

System是jdk自带的一个类,有很多的方法,这些方法都是静态的,也就是static的,out是System提供的用于标准输出的流,在没有重定向的情况下,会直接打印到终端,而println这个方式实际上是PrintStream类提供的功能。

posted on 2018-10-14 11:50  错与对并不是绝对的  阅读(116)  评论(0编辑  收藏  举报

导航