[JAVA] 문자열을 정수로 변환
반응형
숫자로만 이루어진 문자열 n_str이 주어질 때, n_str을 정수로 변환하여 return 코드를 작성하시오
방법1)
public class codetest003 {
public static void main(String[] args) {
System.out.println(solution("20"));
}
public static int solution(String n_str) {
int n = Integer.parseInt(n_str);
return n;
}
}
방법2)
public class codetest003 {
public static void main(String[] args) {
System.out.println(solution("20"));
}
public static int solution(String n_str) {
return Integer.parseInt(n_str);
}
}
반응형
'낙서장[2] > CodeTests' 카테고리의 다른 글
[JAVA] 몫 구하기 (0) | 2025.01.22 |
---|---|
[JAVA] 숫자 비교하기 (1) | 2025.01.21 |
[JAVA] 두 수의 합 (0) | 2025.01.21 |
[JAVA] 두 수의 차 (0) | 2025.01.21 |
[JAVA] 정수를 문자열로 변환 (0) | 2025.01.20 |