728x90
import java.util.Random;
public class Lotto {
public static void main(String[] args) {
new Random().ints(1, 46).distinct().limit(6).sorted().forEach((e) -> {
System.out.printf("%3d", e);
});
}
}
new Random() // 난수 생성기
.ints(1, 46) // 1 ~ 45 사이의 난수 생성(intStream 생성) .distinct() // 중복제거 .limit(6) // 6개만 .sorted() // 정렬 .forEach((e) -> { // 최종연산 : 람다식을 이용한 출력 System.out.printf("%3d", e); // 3칸에 맞추어 정수 출력 }); |
실행결과
728x90
'Java > 잡동사니' 카테고리의 다른 글
십이지신 계산하기 (0) | 2023.02.28 |
---|---|
절대 경로 알아내기 (0) | 2023.02.28 |