求随机数
程序员文章站
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);
}
}//支持多线程