Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert an int integer into an int[] array in Java? Each bit of the integer is each element of the array?
How to convert an int integer into an int[] array in Java? Each bit of the integer is each element of the array?

Integer num = 123456789;//Input number

String str = num.toString();//Convert to string

int[] intArray = new int[str.length()];//Create a new array to save each digit of num

for (int i = 0; i < str.length(); i++) {

// Traverse str and add each digit as intArray

Character ch = str.charAt(i);

intArray[i] = Integer. parseInt(ch.toString());

}

for (int i = 0; i < intArray.length; i++) {

// Traverse Print int[] and check the running results.

System.err.print(intArray[i] + " ");

}