欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

求随机数

程序员文章站 2022-06-17 18:46:20
...

题目描述   

求随机数。

package test3_9;
import java.util.Random;
public class Test3_9 {
    public static void main(String[] args) {
        Random xx=new Random();
        int num=xx.nextInt(10);//范围0~9
        System.out.println("随机数为"+num);
    }  
}

求随机数

package test3_9;
public class Test3_9 {
    public static void main(String[] args) {
        System.out.println(Math.random());//Double型数据
    }  
}

求随机数

package test3_9;
public class Test3_9 {
    public static void main(String[] args) {
        int num=(int)(Math.random()*10);//强制类型转换
        System.out.println(num);
    }
}//支持多线程
求随机数