숫자로만 이루어진 문자열 n_str이 주어질 때, n_str을 정수로 변환하여 return하도록 solution 함수를 완성해주세요.
입출력 예 #1
"10"을 정수로 바꾸면 10입니다.
입출력 예 #2
"8542"를 정수로 바꾸면 8542입니다.
class Solution {
public int solution(String n_str) {
int answer = 0;
return answer;
}
}
class Solution {
public int solution(String n_str) {
int answer = Integer.parseInt(n_str);
return answer;
}
}
숫자로 이루어진 문자열을 정수형으로 변환하는 문제이다.
parselnt() 명령어를 사용해야한다.
parselnt() 기능은 String 타입의 숫자를 int, byte, short 등 숫자타입으로 변환해주는 것이다.
Byte.parseByte(); -> byte 타입으로 전환
Short.parseShort(); -> short 타입으로 전환
Integer.parseInt(); -> int 타입으로 전환
Long.parseLong(); -> long 타입으로 전환
Float.parseFloat(); -> float 타입으로 전환
Double.parseDouble(); -> double 타입으로 전환
(단, String 문자열에 숫자로만 이루어져있어야지만 가능하다)