๊ด€๋ฆฌ ๋ฉ”๋‰ด

ACHO.pk devlog

[Java] ArrayIndexOutOfBoundsException ์—๋Ÿฌ ๋ณธ๋ฌธ

Java

[Java] ArrayIndexOutOfBoundsException ์—๋Ÿฌ

Acho 2023. 3. 30. 18:57

๐Ÿ’กArrayIndexOutOfBoundsException ์—๋Ÿฌ

 

๋ฐฐ์—ด ์ธ๋ฑ์Šค๊ฐ€ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜์„œ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 36

๋Œ€๋ถ€๋ถ„ ์ธ๋ฑ์Šค๋ฅผ ๋ฒ—์–ด๋‚œ ๋ฐฐ์—ด ์š”์†Œ์— ์•ก์„ธ์Šคํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์ด๊ณ , ๋‚˜ ๋˜ํ•œ ๊ทธ๋žฌ๋‹ค.

 

int[] count = new int[55];

๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ๋” ํฌ๊ฒŒ ์ง€์ •ํ–ˆ๋”๋‹ˆ ํ•ด๊ฒฐ๋๋‹ค.


๐Ÿ“Œ๋‚ด๊ฐ€ ๋ฐฐ์—ด ํฌ๊ธฐ๋ฅผ 26์œผ๋กœ ์ƒ์„ฑํ•˜๊ณ , ๋Œ€๋ฌธ์ž์˜ ๊ฒฝ์šฐ ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค๋ฅผ 26~51(์•ŒํŒŒ๋ฒณ 26๊ฐœ)๊นŒ์ง€ ํ• ๋‹นํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฐ์—ด ์ธ๋ฑ์Šค ๋ฒ”์œ„๋ฅผ ๋„˜์–ด์„  ๊ฒƒ์ด์—ˆ๋‹ค.

int[] count = new int[26];

 

์—๋Ÿฌ ์œ„์น˜๋Š”

}else if(ch >= 'A' && ch <= 'Z') {
    count[ch-'A'+26]++;
}

์—ฌ๊ธฐ์˜€๋‹ค. 

 

 

 

'Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Java] InputMismatchException ์—๋Ÿฌ  (0) 2023.03.29
JAVA _๊ธฐ๋ณธ ์ •๋ฆฌ  (0) 2022.01.26
Comments