Java整数的每一个数放到数组

给定一个整数 把整数中包含的每一个数字放到一个数组中 不能使用字符串

你说的啥意思,,所给的整数 有区间限制吗 如果没得用for循环结局。。

使用模进行除就可以了。 或者使用除法也行

是剥离数字吧。
循环用%和/

最容易想到方法是
funciton find(uint num)
{
int mask = 10;
List list = new List();
while(num > mask)
{
int n1 = num % mask ;
int n2 = num / mask;
......
}
}

最容易想到方法是
funciton find(uint num)
{
int mask = 10;
List list = new List();
while(num > mask)
{
int n1 = num % mask ;
int n2 = num / mask;
......
}
}

public class Test {

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    System.out.println("input:");
    int a = scan.nextInt();
    int b[] = new Test().f(a);
    for(int i = 0; i < b.length;i++){
        System.out.print(b[i]+",");
    }

}
public int[] f(int t){
    int[] m = new int[10];
    int i = 0;
    while(t > 0){
        m[i] = t % 10;
        t = t/10;
        i++;
    }

    return m;

}

}

可以考虑这么做,稍微完善了一下。希望能够帮到你。

 import java.util.Arrays;
import java.util.Scanner;

public class TakeOutEachDigitProject {

    public int[] takeOutEachDigit(int t) {
        int[] m = new int[10];//假设整数有这么多位数字
        int i = 0;
        if (t > 0) { // 正整数
            while (t > 0) {
                m[i] = t % 10;
                t = t / 10;
                i++;
            }

        } else if (t < 0) { // 负整数
            t = t
                    * (-1);
            while (t > 0) {
                m[i] = t % 10;
                t = t / 10;
                i++;
            }

        } else { // 0
            i = 1;
            m[i] = 0;
        }
        int[] n = Arrays.copyOfRange(m, 0, i);// 截断数组
        return n;

    }

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        System.out.println("input:");
        int a = scan.nextInt();
        int[] b = new TakeOutEachDigitProject().takeOutEachDigit(a);
        for (int i = b.length - 1; i >= 0; i--) {
            System.out.print(b[i]
                    + ",");
        }

    }

}

图片说明

剥离数字,就是每次都取余10获取个数位,然后除以10让高一位的数字变成个位数,如此循环,直到数字为0

剥离数字,就是每次都取余10获取个数位,然后除以10让高一位的数字变成个位数,如此循环,直到数字为0