java.util.Random 类

//: object/ForEachFloat.java
package object;

import java.util.Random;
public class ForEachFloat
{
    public static void main(String[] args)
    {
        Random rand = new Random();//47是随机种子,如果不提供种子,默认为系统时间
        float f[] = new float[10];
        for(int i = 0; i < 10; i++)
            f[i] =     rand.nextFloat(); //生成0-1之间的float值
        /*nextInt(100)+1  //100 + i是生成的int值的上限(不包括100+i),1为我们设定的下限(包括1),下限默认为0
         * nextLong()
         * nextDouble()
         */
        for(int i = 0; i < 10; i++)
            System.out.printf("%f\t",f[i]);
        System.out.println('\n');
        for(float x : f)  //将f数组的值按顺序赋予x
            System.out.printf("%f\t",x);
    }
}

 

posted @ 2018-11-22 13:51  江期玉  阅读(262)  评论(0编辑  收藏  举报