Board logo

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

作者: tonyh    時間: 2012-9-29 16:33     標題: 亂數 (二)

本帖最後由 tonyh 於 2012-9-29 16:44 編輯

運用Math.random()語法搭配for迴圈,
產生20組範圍介於0.00000~0.99999之隨機亂數.
  1. public class ch31
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {
  7.             System.out.println(Math.random());
  8.         }
  9.     }
  10. }
複製代碼

作者: t2364705    時間: 2012-9-29 16:40

  1. public class ch31
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {
  7.             double x=Math.random();
  8.             System.out.println(x);
  9.         }
  10.     }
  11. }
複製代碼

作者: 劉漢文    時間: 2012-9-29 16:41

  1. public class ch31
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {
  7.             double x=Math.random();
  8.             System.out.println(x);
  9.         }
  10.     }
  11. }
複製代碼

作者: 尤泓鈞    時間: 2012-9-29 16:41

  1. public class ch31
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {
  7.             double x=Math.random();
  8.             System.out.println(x);
  9.         }
  10.     }
  11. }
複製代碼

作者: 蔡昀佑    時間: 2012-9-29 16:41

  1. public class ch31
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {
  7.             double x=Math.random();
  8.             System.out.println(x);
  9.         }
  10.     }
  11. }
複製代碼

作者: t3742238    時間: 2012-9-29 16:46

  1. public class ch31
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {
  7.             double x=Math.random();
  8.             System.out.println(x);
  9.         }
  10.     }
  11. }
複製代碼

作者: 黃博鴻    時間: 2012-10-27 15:10

  1. public class ch31
  2. {
  3.    public static void main(String args[])
  4.    {
  5.      for(int i=1; i<=20; i++)
  6.      {
  7.         System.out.println(Math.random());
  8.      }
  9.    }
  10. }
複製代碼





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