Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 3.請寫一個 Method, 接收最大亂數值、最小亂數值產生一個落在範圍裡的亂數,並印出
- public void printRandom(int max, int min){
- }
- */
- public class LS9HW3{
- public static void main (String args[]){
- // 1 - 666
- int ran = printRandom(1000, 666);
- ezp(ran);
- }
- // Print 方法
- public static void ezp(int content){
- System.out.println(content);
- }
- public static void printRandom(int a, int b){
- int numbers[] = new int[10];
- for(int i = 0 ; i < 10 ; i++){
- double num = Math.random();
- double numDouble = num * a;
- int numInt = (int) numDouble ;
- int ran = numInt ;
- int result = (ran % b) + 1;
- numbers[i] = result;
- }
- Arrays.sort(numbers);
- int max = numbers[9];
- int min = numbers[0];
- }
- }
Add Comment
Please, Sign In to add comment