public class test04 {
public void test01(){
//亂數:Math.random()
double num1 = Math.random(); //初始亂數的范圍是[0,1),是小數,所有定義double型別
System.out.println(num1);
//隨機4位整數
//(Math.random() * 9000)取值的整數范圍是:【0,9000)
//((Math.random() * 9000) + 1000)取值的整數范圍是:【1000,10000)
//((Math.random() * 9000) + 1000)取值的范圍是一個小數,所以要轉換為整數
int num2 = (int)((Math.random() * 9000) + 1000);
System.out.println(num2);
}
public static void main(String[] args){
test04 test = new test04();
test.test01();
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/56658.html
標籤:Java相關
上一篇:哪位大俠知道org.didi.encry.SecurityImpl這個是在哪個jar包嗎?
下一篇:專業選定方向
