🔥새해맞이 특별 라이브 선착순 신청🔥

[인프런 워밍업 스터디 클럽] 백엔드 과제5

문제

imageimage

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println("숫자를 입력하세요 : ");
        Scanner scanner = new Scanner(System.in);
        int numberOfThrows = scanner.nextInt();

        int[] counts = new int[6]; // 각 주사위 횟수를 저장할 배열

        for (int i = 0; i < numberOfThrows; i++) {
            double randomNum = Math.random() * 6;
            int result = (int) randomNum + 1; // 1 ~ 6 사이의 정수로 변환
            counts[result - 1]++; // 카운트
        }

        for (int i = 0; i < counts.length; i++) {
            int count = counts[i];
            System.out.printf("%d은 %d번 나왔습니다.\n", i + 1, count);
        }
    }
}
채널톡 아이콘