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类提供的功能。

原文地址:https://www.cnblogs.com/baimafeima/p/9785799.html