This is a complete Java program doing this:
class X {
public static void main(String[] args) {
int n = 5732;
int len = ((new Integer(n)).toString()).length();
int[] array = new int[len];
for (int i = 0; i < len; i++) {
String x = ((new Integer(n)).toString()).substring(i, i + 1);
array[i] = (new Integer(x)).intValue();
}
}
}
Regards,
Mukul
Bullislander05 wrote:
> Hello,
>
> I'm fairly new to these parts and I come to ask a question.
>
> If anyone here has some experience in programming in Java, I would be
> enlightened to find out if there is any way to extract each digit from
> an integer.
>
> Say there was an integer with a value of 5732, how should I proceed to
> extract the 5, 7, 3, and 2 from said integer and transfer those values
> into an integer array?
>
> If anybody could help me out A.S.A.P I would be very grateful.
>
> Thank you,
> Bullislander05
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---