java RTE 질문 드립니다.

  • fourleaves
    fourleaves

    import java.util.Scanner;
    
    public class Main {
    
        public static void main(String[] args) {
            int end_day[] = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
            Scanner sc = new Scanner(System.in);
            int cases = sc.nextInt();
            while (cases-- > 0) {
                int month = sc.nextInt();
                int last_month = month==1?11:month-2;
                int day = sc.nextInt();
                String week = sc.next();
                int index;
                if(week.equals("Sunday"))
                    index = 1;
                else if(week.equals("Monday"))
                    index = 2;
                else if(week.equals("Tuesday"))
                    index = 3;
                else if(week.equals("Wednesday"))
                    index = 4;
                else if(week.equals("Thursday"))
                    index = 5;
                else if(week.equals("Friday"))
                    index = 6;
                else
                    index = 7;
    
    //          int index = week.equals("Sunday")?1:week.equals("Monday")?2:week.equals("Tuesday")?3:week.equals("Wednesday")?4:week.equals("Sunday")?5:week.equals("Friday")?6:7;
                int weeks[] = new int[7];
                for(int i=1;7>=i;i++){
                    int print = day-index+i<1?end_day[last_month]+(day-index+i):(day-index+i>end_day[month]?day-index+i-end_day[month]:day-index+i);
                    weeks[i-1]=print;
                }
                String output = weeks[0]+" "+weeks[1]+" "+weeks[2]+" "+weeks[3]+" "+weeks[4]+" "+weeks[5]+" "+weeks[6];
                System.out.println(output);
    
            }
        }
    }
    


    주일달력문제입니다.

    자꾸 런타임 에러가 발생하는데 무엇이 문제인지 모르겠네요..
    예상으로는 ""으로 String부분이 에러가 나는것 같은데.. 모르겠네요.. 물논 콘솔이나 이클립스 실행은 잘됩니다.


    9년 전
4개의 댓글이 있습니다.
  • Being
    Being

    12월엔 잘 동작하지 않을 것 같습니다.


    9년 전 link
  • fourleaves
    fourleaves

    12월 에서 1월 잘되고
    12월에서 11월도 잘 됩니다.
    RTE가 문제입니다. ㅠ.ㅠ


    9년 전 link
  • Kureyo
    Kureyo

    배열에서는 월 범위가 1을 뺀 0...11기준인데
    month값은 그대로 참조하고 있지않나요?


    9년 전 link
  • fourleaves
    fourleaves

    그러네요 멍청하게 수정한게 있었는데.. Main class로 된걸 따로하는데 멍청하게 계속 그대로 쓰고 있었네요..
    졸리면 자야지; 다들 ㅈㅅ합니다.


    9년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.