Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/main/java/kr/easw/lesson3/RollTheDice.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ public static void main(String[] args) {
*
* 또한, 입력값이 double임으로 60으로 나눈 이후 int로 캐스팅이 필요합니다.
*/

private static void fillArray(double result) {
throw new RuntimeException("이 코드 라인을 지우고, 이곳에서 작성하십시오.");
int index = (int) (result / 60); // 주어진 값을 60으로 나눈 후 캐스팅하여 인덱스로 사용
if (index >= frequency.length) {
frequency = extendArray(index + 1);
}
frequency[index]++; //해당 인덱스의 값 증가
}

/**
* 해당 메서드는 다음과 같은 역할을 가져야 합니다 :
* 주어진 값의 크기만큼 배열을 생성한 후, 기존 배열에 있던 데이터를 복사해 반환해야 합니다.
*/
private static int[] extendArray(int next) {
throw new RuntimeException("이 코드 라인을 지우고, 이곳에서 작성하십시오.");
int[] newArray = new int[next];
System.arraycopy(frequency, 0, newArray, 0, frequency.length); //배열 복사
return newArray;
}
}
}