Math.random() 와 HastSet 으로 구현된 클래스 임의의 숫자 1 ~ 45 를 추출하여 HashSet에 저장한다. HashSet은 중복을 허용하지 않기 때문에 알아서 중복된 숫자가 추출될 경우를 걸러내어 준다.
// LottoNumber.class
 

public class LottoNumber {

	public static void main(String[] args) {
		
		HashSet set = new HashSet();
		
		
		while(set.size()<=6) {
			set.add((int)(Math.random() * 44) + 1);
		}
		
		for(int a : set) {
			System.out.println(a);
		}
		
	}
}

posted by 쪼재