본문 바로가기
혼자 공부하는 것들/JAVA

JAVA) 로또 번호 생성기 +HashSet 사용

by applepick 2020. 7. 18.
반응형

HashSet을 통해서 로또번호 생성기를 만들어보았습니다.

import java.util.*;

public class Lotto645
{
    public static void main( String[] args )
    {
        HashSet<Integer> hset = new HashSet<Integer>();
        Random rand = new Random();

        while( hset.size() < 6 ) 
        {
            int number = 1 + rand.nextInt(45);
            hset.add( number );
        }
        System.out.println( hset );
    }
}
반응형

댓글