# 주사위 통계 코드 맞게 작성한 것 같은데 어디에서 오류나는지 모르겠어요.. #### CODE <a class='btn btn-default' href='/codes/24915'>Link</a> ``` // 자바 API를 불러옴 import java.lang.Math; import java.util.Random; public class RandomTest { public static void main(String[] args) { // 변수 생성 및 주사위 던지기 int[] count = new int[13]; // 0~12 for(int i=0; i<100; i++){ int a = DieA.roll(); int b = DieB.roll(); count[a+b]++; } // 결과 출력 for(int row=2; row<count.length; row++){ System.out.printf("%2d => ", row); for(int col=0; col<count[row];col++){ System.out.printf("#"); } System.out.println(); } } class DieA { // 1 부터 6사이 정수를 반환 [참고] https://cloudstudying.kr/challenges/348 public static int roll() { double r = Math.random() * 6; // 0.0 <= r < 6.0 int randInt = (int) r; // 0, 1, 2, ..., 5 return randInt + 1; // 1, 2, 3, ..., 6 } } class DieB { public static int roll() { // 1 부터 6사이 정수를 반환 [참고] https://cloudstudying.kr/challenges/404 Random rand = new Random(); int randInt = rand.nextInt(6); // (0 ~ 5) return randInt + 1; } } } ``` #### INPUT ``` ``` #### OUPUT ``` /root/var/tmp/2020_05_15_08_16_00_7983428e/RandomTest.java:28: error: Illegal static declaration in inner class RandomTest.DieA public static int roll() { ^ modifier 'static' is only allowed in constant variable declarations /root/var/tmp/2020_05_15_08_16_00_7983428e/RandomTest.java:36: error: Illegal static declaration in inner class RandomTest.DieB public static int roll() { ^ modifier 'static' is only allowed in constant variable declarations 2 errors ```
# DieA 및 DieB 클래스를 RandomTest클래스 밖으로 꺼내보세요
DieA.roll(); => DieA클래스에 선언된 roll 메소드를 호출하고 있습니다. 그런데 현재 작성하신 코드에는 DieA클래스가 RandomTest클래스의 main메소드 안에 있습니다. 클래스 안에 또 다른 클래스를 선언할수 없기때문에 roll 메소드를 호출할수 없다는 에러가 발생하는 것입니다. 그러므로 RandomTest클래스안에 있는 DieA 와 DieB클래스를 RandomTest클래스 바깥으로 빼줘야 합니다.