Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

코딩응급실

프로그래머스: 자연수 뒤집어 배열로 만들기 본문

Java

프로그래머스: 자연수 뒤집어 배열로 만들기

Daeryuk Kim 2024. 3. 2. 16:12
import java.util.*;

class Solution {
    public int[] solution(long n) {
        String str = new StringBuilder(String.valueOf(n)).reverse().toString();
        int[] answer = new int[str.length()];
        
        for (int i = 0; i < str.length(); i++) {
            answer[i] = str.charAt(i) - '0';
        }
        
        return answer;
    }
    public static void main(String[] args) {
        long n = 12345;
        Solution sol = new Solution();
        int[] result = sol.solution(n);
        
        // 배열 출력
        for (int i : result) {
            System.out.print(i + " ");
        }
    }
}