Friday, 15 January 2010

java - How do I use modulus in a while loop to get individual digits of an integer? -



java - How do I use modulus in a while loop to get individual digits of an integer? -

i'm hoping find way utilize while loop (not loop) individual digits of integer set in through command line. right now, have hard coded how individual digits if 4 digit integer entered, if come in 5 digit number won't work. i'm thinking while loop should able prepare i'm not sure how...

here code have far

try this:

list<integer> digits = new arraylist<integer>(); while (number > 0) { digits.add(number%10); number /= 10; }

java while-loop modulo modulus integer-division

No comments:

Post a Comment