array coerce int code example

Example 1: java int to int array

int number = 110101; 
String temp = Integer.toString(number);
int[] numbers = new int[temp.length()];
for (int i = 0; i < temp.length(); i++) {
    numbers[i] = temp.charAt(i) - '0';
}

Example 2: how to convert a multy digit array into a whole number

var wholeNumber = 0;
var array = [ 5, 6, 2 ];
for(var dummyVariable = 0; dummyVariable < array.length-1; dummyVariable++){
	array[dummyVariable] = power(10, array.length-dummyVariable-1) * array[dummyVariable];
    //						   number, exponent
    wholeNumber+=array[dummyVariable];
}
//Written And Tested In Pre-ES6 Javascript.

Tags:

Java Example