문자열 s를 숫자로 변환하는 문제이다. s는 0으로 시작하지 않고, 숫자로만 이루어져있으면 맨앞에 부호가 올 수 있다.
public class StringToInteger {
public int solution(String s) {
int answer = Integer.parseInt(s);
return answer;
}
}
숫자로 변환하는 방법에는 Integer.parseInt(), Integer.valueOf()가 있다. 하지만 parseInt()는 반환값이 int이고, valueOf()의 반환값은 Integer이다.