Skip to content

Latest commit

ย 

History

History

P15740

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
ย 
ย 
ย 
ย 
ย 
ย 

[baekjoon-15740] A+B - 9

image

๋ฌธ์ž์—ด ํ’€์ด๋กœ ๊ตฌํ˜„ํ•œ ๋ง์…ˆ, ๋บ„์…ˆ

์ข€ ํŠน์ดํ•œ ๋ฌธ์ œ์˜€๋‹ค. ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์ž…๋ ฅ ์ˆซ์ž์˜ ๊ธธ์ด๊ฐ€ ๋งค์šฐ ํฌ๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋ƒฅ + operator๋ฅผ ์‚ฌ์šฉํ•ด ๋Œ๋ฆฌ๋ฉด Integer.parseInt ๋ฉ”์„œ๋“œ๋ฅผ ์“ธ ๋•Œ java.lang.NumberFormatException์ด ๋ฐœ์ƒํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฌธ์ž์—ด์„ ์‚ฌ์šฉํ•ด ํ’€์—ˆ๊ณ , ๊ทธ ๋•Œ๋ฌธ์— ๋ฌธ์ž์—ด ๋ฌธ์ œ๋กœ ๋ถ„๋ฅ˜ํ•ด๋ณด์•˜๋‹ค.

image

BigInteger

ํ—ˆ๋ฌดํ•˜๊ฒŒ๋„ ๋‹ค๋ฅธ ํ’€์ด๋ฅผ ์ฐพ์•„๋ดค์„ ๋•Œ, java.math.BigInteger ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์—ˆ๋‹ค. ใ… ใ…  ๊ทธ๋ž˜๋„ ์‹œ๊ฐ„์€ ๋‚ด ํ’€์ด๊ฐ€ ์ง„์งœ ๋น ๋ฅด๋‹ค !!! ใ… ใ… 

import java.math.BigInteger;

// ...

BigInteger a = new BigInteger(st.nextToken());
BigInteger b = new BigInteger(st.nextToken());
System.out.println(a.add(b));