java Ranbom类

本文介绍了Java中的Random类及其主要成员方法,如nextBoolean()用于生成布尔值,nextDouble()生成0到1之间的double值,nextInt()和nextLong()生成整数,以及nextInt(intn)生成指定范围内的整数。示例代码展示了如何在`Ranbom2`类中使用这些方法。
摘要由CSDN通过智能技术生成

Ranbom类的主要成员方法:

public boolean nextBoolean().//随机生成boolean值
public double nextDouble().//随机生成【0,1】的double值
public float nextFloat().//随机生成【0,1】的flaot值
public int nextInt().//随机生成int值
public int nextInt(int n).//随机生成不大于n的int值
public long nextLong().//随机生成long值
package store.coffer;
import java.util.Random;
public class Ranbom2 {
    public static void main(String[] args) {
        Random random = new Random();
        System.out.println(random.nextFloat());
        System.out.println(random.nextDouble());
        for(int i=0;i<5;i++){
            System.out.println(random.nextInt(20)+"\t");
        }
    }
}

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值