Board logo

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

作者: tonyh    時間: 2017-2-25 10:35     標題: 亂數 (二)

運用 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.             System.out.println(Math.random());
  7.     }
  8. }
複製代碼

作者: 黃茂勛    時間: 2017-2-25 10:53

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

作者: 陸長辰    時間: 2017-2-25 10:54

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

作者: 林侑成    時間: 2017-2-25 10:56

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

作者: 陳泓瑜    時間: 2017-2-25 11:01

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





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