문제1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int inputDice = inputPrint();
int[] dice = rollDice(inputDice);
OutPutPrint(dice);
}
private static int inputPrint() {
Scanner scanner = new Scanner(System.in);
System.out.print("숫자를 입력하세요 : ");
return scanner.nextInt();
}
private static int[] rollDice(int inputDice) {
int[] dice = new int[inputDice];
for (int i = 0; i < dice.length; i++) {
int num = (int) (Math.random() * inputDice) + 1;
dice[num - 1] ++;
}
return dice;
}
private static void OutPutPrint(int[] dice) {
for (int i = 0; i < dice.length; i++) {
System.out.printf("%d는 %d번 나왔습니다.\n", i + 1, dice[i]);
}
}
}
계층늘나눠서 만드는게 보는입장에서 그게더 복잡할거같다고 생각했기에 메소드만 나눠서 만들었다.
입력 함수 , 기능함수 , 출력함수 3개로 나눠서 만들었다.
'인프런 워밍업 스터디 > 과제' 카테고리의 다른 글
[인프런 워밍업 스터디 클럽 0기 - BE] #7 과제 (0) | 2024.02.27 |
---|---|
[인프런 워밍업 스터디 클럽 0기 - BE] #6 과제 (0) | 2024.02.26 |
[인프런 워밍업 스터디 클럽 0기 - BE] #4 과제 (0) | 2024.02.22 |
[인프런 워밍업 스터디 클럽 0기 - BE] #3 과제 (0) | 2024.02.21 |
[인프런 워밍업 스터디 클럽 0기 - BE] #2 과제 (0) | 2024.02.20 |