aspose file tools*
The moose likes Beginning Java and the fly likes How to convert a number into an Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert a number into an Array" Watch "How to convert a number into an Array" New topic
Author

How to convert a number into an Array

Nagaraju Pee
Greenhorn

Joined: Feb 13, 2010
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.

please help me at this context
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
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

Joined: Aug 08, 2008
Posts: 30
    
    1

hi apply
this modulas logic

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

Ravi Shankar Kumar
SCJP 1.5, (Following-OCWCD)
 
Consider Paul's rocket mass heater.
 
subject: How to convert a number into an Array