2019.12.09 Random 随机数类

//导包
import java.util.Random;
class Demo02
{
  public static void main(String[] args)
  {
    //创建Random对象
    Random r=new Random();
    //调用方法

    //生成0-9,之间的随机整数,不包括9
    int num=r.nextInt(9);
    System.out.println(num);
  }
}

//导包
import java.util.Random;
class Demo02
{
  public static void main(String[] args)
  {
    //创建Random对象
    Random r=new Random();
    //调用方法
    //生成随机小数
    double num=r.nextDouble();
    System.out.println(num);
  }
}

猜你喜欢

转载自www.cnblogs.com/l1314/p/12009179.html