Here you can find the source of numberToDigits(int num)
public static int[] numberToDigits(int num)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import java.util.ListIterator; public class Main { public static int[] numberToDigits(int num) { if (num < 0) { throw new IllegalArgumentException("num should not be negative"); }/*from w w w. j av a 2 s .co m*/ final int RADIX = 10; List<Integer> list = new ArrayList<Integer>(); while (num > 0) { list.add(num % RADIX); num /= RADIX; } int[] ret = new int[list.size()]; ListIterator<Integer> itr = list.listIterator(); while (itr.hasNext()) { int idx = itr.nextIndex(); ret[idx] = itr.next(); } return ret; } }