[Java] Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException - ๋ฐฐ์—ด ์„ ์–ธ

epiphanyยท2022๋…„ 10์›” 18์ผ
0

Programmers School

๋ชฉ๋ก ๋ณด๊ธฐ
2/22
post-thumbnail

Programmers School์—์„œ Lv0 ์ฝ”๋”ฉ ๊ณผ์ •์—์„œ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜ ์ •๋ฆฌ

๐Ÿ“ข ๋ฌธ์ œ

๋ฐฐ์—ด์— ๊ฐ’์„ ๋„ฃ๋Š” ๋ถ€๋ถ„์—์„œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

๐Ÿ“– ์›์ธ

๋ฐฐ์—ด ์„ ์–ธ์‹œ ์ดˆ๊ธฐํ™”๋ฅผ ํ•ด์ฃผ์ง€ ์•Š์•„ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜

๐Ÿ’ก ํ•ด๊ฒฐ

๋ฐฐ์—ด ์ƒ์„ฑํ•˜๋Š” ๋ถ€๋ถ„์— strlist๋ฐฐ์—ด ์‚ฌ์ด์ฆˆ๋กœ ์ดˆ๊ธฐํ™” ์„ ์–ธํ•ด์ฃผ๊ธฐ

// ์ตœ์ข… ์ฝ”๋“œ
class Solution {
    public int[] solution(String[] strlist) {
        int[] answer = new int[strlist.length];
        for(int i=0;i<strlist.length;i++){
            if (1<=strlist[i].length() && strlist[i].length()<=100){
                answer[i] = strlist[i].length();
            }
        }
        return answer;
    }
}

0๊ฐœ์˜ ๋Œ“๊ธ€