Computer Science Canada Method for breaking a number into its digits |
Author: | Naveg [ Fri Sep 15, 2006 11:22 pm ] |
Post subject: | Method for breaking a number into its digits |
Does java have a method that will do this? I can easily code this myself, but I was wondering if it was already a part of the java library. Essentially you pass a number to the method and it returns an array of ints consisting of the individual digits. |
Author: | wtd [ Sat Sep 16, 2006 8:24 am ] |
Post subject: | |
I don't believe this is a part of the library. |
Author: | r.3volved [ Sat Sep 16, 2006 11:13 am ] |
Post subject: | |
no it doesn't this was talked about just the other day here in another thread... use modulus to pick out each integer |
Author: | Naveg [ Sat Sep 16, 2006 5:14 pm ] |
Post subject: | |
yea, i know how to do it - its really easy. Its just that i need to work with digits in many of of my programs, so it would be nice if it were a part of the library. |
Author: | r.3volved [ Sat Sep 16, 2006 5:56 pm ] |
Post subject: | |
just make yourself an extended class and keep it around to include where you need it... thats what oop is all about |
Author: | bugzpodder [ Sat Sep 16, 2006 8:08 pm ] |
Post subject: | |
Integer.parseInt(myInteger).charAt(i) |
Author: | bugzpodder [ Sat Sep 16, 2006 8:09 pm ] |
Post subject: | |
return (myInteger/Math.pow(10,i))%10 |