This week's book giveaways are in the Refactoring and Agile forums.We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

# How to convert a number into an Array

Nagaraju Pee
Greenhorn
Posts: 5
Hi,
How can i convert a number into an array?

for ex: I have a number 34567.Now i want to convert that number into an array which has values like this
array[0]=3,array[1]=4,array[2]=5 and so on.

D. Ogranos
Ranch Hand
Posts: 214
What format should your result array have? A String array, or an int array?

If you need a string array, then simply convert the number to a string and grab its characters with the charAt() method (or substring()) of the String class.

Else, you need to use divison by 10 repeatedly to find the digit values (for example, 34567 / 10000 = 3, then go on with the rest, 4567 / 1000 = 4, and so on).

Ravi Shankar Kumar
Ranch Hand
Posts: 30
1
hi apply
this modulas logic

do {
arr[i] = number % 10;
number /= 10;
i++;
} while (number != 0);