daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 3.請寫一個 Method, 接收最大亂數值、最小亂數值產生一個落在範圍裡的亂數,並印出
  3. public void printRandom(int max, int min){
  4. }
  5. */
  6.  
  7. public class LS9HW3{
  8.  
  9.   public static void main (String args[]){
  10.  
  11.      // 1 - 666
  12.      int ran = printRandom(1000, 666);
  13.  
  14.      ezp(ran);
  15.  
  16.   }
  17.  
  18.   // Print 方法
  19.   public static void ezp(int content){
  20.       System.out.println(content);
  21.   }
  22.     public static void printRandom(int a, int b){
  23.  
  24.         int numbers[] = new int[10];
  25.  
  26.         for(int i = 0 ; i < 10 ; i++){
  27.  
  28.             double num = Math.random();
  29.             double numDouble = num * a;
  30.  
  31.             int numInt = (int) numDouble ;
  32.  
  33.             int ran = numInt ;
  34.             int result = (ran % b) + 1;
  35.             numbers[i] = result;
  36.         }
  37.         Arrays.sort(numbers);
  38.         int max = numbers[9];
  39.         int min = numbers[0];
  40.  
  41.  
  42.     }
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top