Board logo

標題: 亂數 (一) [打印本頁]

作者: tonyh    時間: 2020-11-21 11:18     標題: 亂數 (一)

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

作者: 龔品誠    時間: 2020-11-21 11:43

  1. public class OUO
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         double r;
  6.         r=Math.random();
  7.         System.out.println(r);
  8.     }
  9. }
複製代碼

作者: 朱閎聿    時間: 2020-11-21 11:43

  1. public class Ch05
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         double r;
  6.         r=Math.random();
  7.         System.out.println(r);
  8.     }
  9. }
複製代碼

作者: 林羿丞    時間: 2020-11-21 11:44

  1. public class Ch666
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         double r;
  6.         r=Math.random();
  7.         System.out.println(r);
  8.     }
  9. }
複製代碼

作者: 王銘鴻    時間: 2020-11-21 11:45

  1. public class Ch30
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         double r;
  6.         r=Math.random();
  7.         System.out.println(r);
  8.     }
  9. }
複製代碼

作者: 陳莉榛    時間: 2020-11-21 11:45

  1. public class Ch555
  2. {
  3.     public static void main(String args[])
  4.     {
  5.     double r;
  6.     r = Math.random();
  7.     System.out.print(r);

  8. }
  9. }
複製代碼

作者: 李穎俊    時間: 2020-11-21 11:47

  1. public class d
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         double d;
  6.         d=Math.random();
  7.         System.out.println(d);
  8.     }
  9. }
複製代碼

作者: 黃柏智    時間: 2020-11-28 09:43

  1. public class A02
  2. {
  3.   public static void main(String args[])
  4.   {
  5.     double r;
  6.     r= Math.random();
  7.     System.out.println(r);
  8.   }
  9. }
複製代碼

作者: 張淯祺    時間: 2020-11-30 18:22

  1. public class h2
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         System.out.println(Math.random());
  6.     }
  7. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2