I beg
to differ. What get's printed out is:
digit
= 1
digit = 2
digit = 3
digit = 2
digit = 3
Works
fine.
looking at the logic:
digit
= 1 is remainder of 321 / 10
divide
321 by ten and you're left with 32
digit = 2 is remainder if 32 / 10
digit = 2 is remainder if 32 / 10
divide
32 by ten and you're left with 3
digit = 3 is remainder of 3 / 10
digit = 3 is remainder of 3 / 10
divide
3 by ten and you're left with 0
exit
the loop
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm-----Original Message-----
From: Anthony Grace [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 05, 2002 12:34 PM
To: JDJList
Subject: [jdjlist] Re: Getting digits from an integerThat's my point. So what we get printed out is:
3, 2, 0
...whereas Jeff wanted to get:
3, 2, 1 ??
Maybe I missed something here?
Paul Franz <[EMAIL PROTECTED]>wrote:
Dividing by 10 makes it 0.Paul FranzTo change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm----- Original Message -----From: Anthony GraceTo: JDJListSent: Thursday, September 05, 2002 10:58 AMSubject: [jdjlist] Re: Getting digits from an integerwhat 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
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
