문제 설명

솔루션
import java.util.*;
class Solution {
public int[] solution(long n) {
String str = String.valueOf(n);
StringBuilder sb = new StringBuilder(str);
sb = sb.reverse();
String[] str_arr = sb.toString().split("");
int[] answer = new int[str_arr.length];
for(int i = 0; i < str_arr.length; i++){
answer[i] =Integer.parseInt(str_arr[i]);
}
return answer;
}
}
다른 풀이
class Solution {
public int[] solution(long n) {
String a = "" + n;
int[] answer = new int[a.length()];
int cnt=0;
while(n>0) {
answer[cnt]=(int)(n%10);
n/=10;
System.out.println(n);
cnt++;
}
return answer;
}
}'java' 카테고리의 다른 글
| [프로그래머스 - 자바] 정수 제곱근 판별 (0) | 2023.09.19 |
|---|---|
| [프로그래머스 - 자바] 문자열 내 p와 y의 개수 (0) | 2023.09.19 |
| [프로그래머스 - 자바] x만큼 간격이 있는 n개의 숫자 (0) | 2023.09.19 |
| [프로그래머스 - 자바] 약수의 합 (0) | 2023.09.19 |
| [프로그래머스 - 자바] 자릿수 더하기 (0) | 2023.09.19 |