JAVA - HashSet을 이용한 로또 번호 생성하는 프로그램(2022-07-25)

2022. 7. 25. 21:483층 1구역 - 개발의 장/JAVA

package hashSets;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;

public class Quiz01 {

	public static void main(String[] args) {
		/*
		 * HashSet을 이용하여 로또 번호 6개 출력하기
		 */

		HashSet hs = new HashSet();

		while (hs.size() < 6) {
			hs.add((int) (Math.random() * 45) + 1);
		}
		// System.out.println(hs); //그냥 출력

		ArrayList<Integer> list = new ArrayList<>(hs);
		list.sort(null);
		System.out.println(list); //오름차순으로 출력

	}

}