public class Test{public String print(int num){while(num>0){System.out.print(num%10+",");num/=10;}}public static void main(String [] args){Test t = new Test();t.print(12345);}}
先将这个数转换成字符串,判断其长度,根据长度判断该数的级别,如该数是1230023,那么他的长度是8,那么该数是八位,然后循环使用 String 中的substring(int beginIndex, int endIndex) 取出如下:int num1 = 1230023;String str = new String(num1);int l = str.length();char[] c = new char[l];for(int i = 1 ; i < l ; i++){c[i-1] = str.substring(i,i);System.out.println(c[i-1]);}