๊ด€๋ฆฌ ๋ฉ”๋‰ด

JiYoung Dev ๐Ÿ–ฅ

[JAVA] long ํƒ€์ž…์—์„œ String ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ ๋ณธ๋ฌธ

Question

[JAVA] long ํƒ€์ž…์—์„œ String ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ

Shinjio 2023. 8. 7. 08:49

String.valueOf(N)

 

import java.util.*;

class Solution {
    public int[] solution(long n) {
        
        String s = String.valueOf(n);
        int idx = s.length();
        
        int[] answer = new int[idx];
        
        for(int i = 0 ; i < idx ; i++){
            answer[i] = (int)(n % 10);
            n /= 10;
        }
        
        return answer;
    }
}