본문 바로가기

개발과/이 문제 알고리쯤?

문자열을 정수로 바꾸기 : java


//문자열을 정수로 바꾸기
//문자열 s 를 숫자로 변환하기 (형변환) 문자를 > 숫자로, 숫자를 > 문자로는 할줄 아는가?

import static java.lang.Integer.parseInt;

class Solution {
public int solution(String s) {
int answer =0;
answer=Integer.parseInt(s); //문자를 숫자로 형변환하는 메서드 parseInt.() 몰랐던 부분!!
return answer;
}
}

// int i String s로 바꿔보기
//class Solution {
// public int solution(int i) {
// String answer ="";
// s = Integer.tostring(i); //숫자를 문자로 형변환하는 메서드 toString.() 몰랐던 부분!!
// answer+=i
// return answer;
// }
//}

'개발과 > 이 문제 알고리쯤?' 카테고리의 다른 글

가운데 글자 뽑아내기 : java  (0) 2023.04.09
홀수와 짝수 : java  (0) 2023.04.09
두 정수 사이의 합 : java  (0) 2023.04.09
평균구하기 : java  (0) 2023.04.09
핸드폰 번호가리기 : java  (0) 2023.04.09