๐ฟ ๋ฌธ์ ๐ฟ
์ซ์๋ก๋ง ์ด๋ฃจ์ด์ง ๋ฌธ์์ด n_str์ด ์ฃผ์ด์ง ๋, n_str์ ์ ์๋ก ๋ณํํ์ฌ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
[Algorithm]
์ ์๋ก ๋ณํํ๋ ํ๋ณํ ๋ค์ํ ๋ฐฉ๋ฒ ์๊ฐ !
1. Integer.parseInt(value)
2. Integer.valueOf(value)
[Code]
// 1. Integer.parseInt()
class Solution {
public int solution(String n_str){
return Integer.parseInt(n_str);
}
}
// 2. Integer.valueOf()
class Solution {
public int solution(String n_str){
return Integer.valueOf(n_str);
}
}
[+ Plus]
โญ๏ธ ํ๋ณํ(casting)
: ์ ์์์ ๋ฌธ์์ด, ๋ฌธ์์ด์์ ์ ์๋ก ํ์ ๋ณํํ ๋๋ Java ๋ด์ฅ ํด๋์ค์ธ Integer์ ๋ฉ์๋ ์ฌ์ฉ
โก๏ธ String to Int - Integer.parseInt()
Int to string - Integer.toString()
* Stringํด๋์ค์ ๋ฉ์๋ valueOf๋ ์ฌ์ฉ ๊ฐ๋ฅ