1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 
package com.test;
 
import java.util.Random;
 
public class Random {
    
    public static void main(String[] args) {
        
        //난수 생성기
        //    - 임의의 수를 발생 시키는 생성기
        //    - Random 클래스
        //    - 특성
        
        //동시 임포트] Ctrl + Shift + O 
        
        
        //Ex]
        Random rnd = new Random();
        //int n= rnd.nextInt();     //임의의 수 1개를 반환(int 범위내의)
        //System.out.println(n);
        
            //제어., (연속된)범위설정
            for (int i=0; i<10; i++) {    //로또생성기st..
                //0~9 난수생성
                int n = rnd.nextInt(10);
                System.out.println(n);
                
                
                //1~14
                //int n = rnd.nextInt(10);
                //n++;
                
                //1~10
                //int n = rnd.nextInt(10) +1;
                
                //5~12
                //int n = rnd.nextInt(16) +5; 
                
                //5~12 15~20
                //int n = rnd.nextInt(10) +1; //이런거 안된다고..
                /* int[] nums = {5,6,7,8,9,10,11,12,13,14,15,16,17,18,1,20}; //쓰고 싶으면 이렇게., 난수를 방번호로 쓰겠다.
                int index = rnd.nextInt(nums.length); //이중에 방번호 하나를 주겠다.
                System.out.println(nums[index]);
                
                String[] names = {"홍길동", "아무게", "하하하"};
                int index2 = rnd.nextInt(names.length);
                System.out.println(nums[index2]); */
                
                                
                    //예제
                    System.out.println(rnd.nextDouble());
                    System.out.println(rnd.nextDouble()); //0~1
            }
    }
 
}
 
cs


'WEB > JAVA' 카테고리의 다른 글

CLASS  (0) 2015.05.22
PACKAGE  (0) 2015.05.22
ARAARY(배열)  (0) 2015.05.22
CALENDAR  (0) 2015.05.22
StringBuilder  (0) 2015.05.22

+ Recent posts