个位:数值%10
十位:数值/10%10
百位:数值/100%10
千位:数值/1000%10
...
若要取出x的每位数字则代码如下:
int count=0; int temp=code;//临时设置一个变量记录code while (code!=0){ code/=10;//每次循环去掉右边的一个数字 count++;//去掉一个数字计数器就自增一次 } int []arr=new int[count]; while (temp!=0){//将每个位置的数存入数组 arr[i++]=temp%10; temp/=10; }
tips:个位数在数组中是逆序的