返回列表 發帖

亂數 (二)

運用 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. }
複製代碼

  1. public class Ch02 {
  2.         public static void main(String[] args) {
  3.                 for(int i=1; i<=20; i++)
  4.                         System.out.println(Math.random());
  5.         }

  6. }
複製代碼

TOP

  1. public class Ch03 {

  2.         public static void main(String[] args) {
  3.                 for(int i=1; i<=20; i++)
  4.                         System.out.println(Math.random());

  5.         }

  6. }
複製代碼

TOP

  1. public class Ch03
  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. }
複製代碼

TOP

  1. public class Ch02
  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. }
複製代碼

TOP

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

TOP

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

TOP

  1. public class A01 {

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

  9. }
複製代碼

TOP

本帖最後由 楊小萱 於 2021-1-26 10:07 編輯
  1. public class Ch05
  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.        
  9. }
複製代碼

TOP

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

TOP

  1. public class Ch11
  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. }
複製代碼

TOP

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

  8. }
複製代碼

TOP

返回列表