返回列表 發帖

亂數 (一)

本帖最後由 tonyh 於 2014-11-22 16:48 編輯

運用 random() 函式, 產生一範圍介於 0.00000 (趨近於0) ~ 0.99999 (趨近於1) 之隨機亂數.
用此語法產生的亂數, 其資料形態為 double.
  1. //import java.lang.Math;
  2. public class ch30
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          double x=Math.random();
  7.          System.out.println(x);
  8.     }
  9. }
複製代碼

返回列表