DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

Thread: single out digits from a three digit number

1. danny herrera Guest

single out digits from a three digit number

how would i about determining whether the digits in a three digit number are
odd or even. i thought this code might work but im not sure.

num == 123
digit1 == num % 10 = 3
num == num / 10 = 12
digit2 == num % 10 = 2
num == num / 10 = 1
digit3 == num % 10 = 1

2. naomi Guest

Re: single out digits from a three digit number

"danny herrera" <danny.herrera4@gte.net> wrote:
>
>how would i about determining whether the digits in a three digit number

are
>odd or even. i thought this code might work but im not sure.
>
>num == 123
>digit1 == num % 10 = 3
>num == num / 10 = 12
>digit2 == num % 10 = 2
>num == num / 10 = 1
>digit3 == num % 10 = 1

num = 123
digit1 = ((num % 2) == 1)
num = num / 10
digit2 = ((num % 2) == 1)
num = num / 10
digit3 = ((num % 2) == 1)

digit1,2 and 3 are boolean and true if the digit is odd

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts

 FAQ Latest Articles Java .NET XML Database Enterprise