当先锋百科网

首页 1 2 3 4 5 6 7

实例

例1

输入:[4,3,2,1] 

输出:[4,3,2,2]

例2

输入:[4,3,2,2] 

输出:[4,3,2,3]

例3

输入:[9,9] 

输出:[1,0,0]

实现逻辑


    public static void main(String[] args) {
        int[] a2 = {8,9,9,9};
        int[] a3 = getInts(a2);
        System.out.println(Arrays.toString(a3));
    }

    private static int[] getInts(int[] a2) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int j : a2) {
            stringBuilder.append(j);
        }
        int anInt = Integer.parseInt(stringBuilder.toString());
        anInt++;
        String s = String.valueOf(anInt);
        int[] a3 = new int[s.length()];
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            a3[i] = Integer.parseInt(String.valueOf(c));
        }
        return a3;
    }