|
Dividing by 10 makes it 0.
Paul Franz
----- Original Message -----
Sent: Thursday, September 05, 2002 10:58
AM
Subject: [jdjlist] Re: Getting digits
from an integer
what happens when number=1 on the final pass?
Paul Franz <[EMAIL PROTECTED]>wrote:
You
need to do the following:
while (number !=
0) { System.out.println ("digit = "+(number % 10)); number /=
10; }
The >> is a binary shift operator.
Paul
Franz ----- Original Message ----- From: "Jeff Fisher"
<[EMAIL PROTECTED]> To: "JDJList"
<[EMAIL PROTECTED]> Sent: Wednesday, September 04, 2002 7:59
AM Subject: [jdjlist] Getting digits from an integer
> I
need to be able to get each individual digit from an integer as an >
integer. I think I should be able to do this by using the >>
operator, but > I just can't seem to figure it out. > >
For example if I have a number 123, I need to get 3, then the 2, then
the 1. > It doesn't really matter the order, I just need the
digits. I suppose I > could convert it to a string and go that route,
but that seems ! like a waste. > > Does anyone have
experience with this or can point me to some >
examples/information. > > Thanks > >
Jeff > > To change your JDJList options, please
visit: http://www.sys-con.com/java/list.cfm >
To change
your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Do You Yahoo!? Yahoo!
Finance - Get real-time stock quotes To change your JDJList options,
please visit: http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm
|