문제 & 예시
소스코드
import java.util.Arrays;
// 자연수 뒤집어 배열로 만들기
public class test13 {
public static void main(String[] args) {
Solution13 sol = new Solution13();
long n = 12345;
System.out.println(sol.solution(n));
}
}
class Solution13 {
public int[] solution(long n) {
// n의 길이를 (int)Math.log10(n)+1 이용하여 얻음
int[] answer = new int[(int)Math.log10(n)+1];
long temp = 0; // 자릿수를 담기위한 변수
int cnt = 0;
// n값을 쪼개기 위한 반복문
while(0<n) {
temp = n % 10;
n = n / 10;
answer[cnt++] = (int)temp;
}
// System.out.println(Arrays.toString(answer));
return answer;
}
}