Jump to content

even or uneven number?

Go to solution Solved by Nineshadow,
if(<int> % 2 == 0)

Modulo (%) gives you the remainder .

 

Or, using bitwise operations :

if(<int> & 1)

I am programming with Processing 3 (Java) and I am searching for a formula to tell me if a number is even or uneven and I need it to fit into a

if(...) { ... } else { ... } type-contruction.

please help me.

http://linustechtips.com/main/topic/334934-unofficial-ltt-beginners-guide/ (by Minibois) and a few things that will make our community interaction more pleasent:
1. FOLLOW your own topics                                                                                2.Try to QUOTE people so we can read through things easier
3.Use
PCPARTPICKER.COM - easy and most importantly approved here        4.Mark your topics SOLVED if they are                                
Don't change a running system

Link to comment
https://linustechtips.com/topic/485844-even-or-uneven-number/
Share on other sites

Link to post
Share on other sites

if(<int> % 2 == 0)

Modulo (%) gives you the remainder .

 

Or, using bitwise operations :

if(<int> & 1)

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
https://linustechtips.com/topic/485844-even-or-uneven-number/#findComment-6514382
Share on other sites

Link to post
Share on other sites

if(<int> % 2 == 0)

Modulo (%) gives you the remainder .

 

Or, using bitwise operations :

if(<int> & 1)

goddamnit,we already learned that :/

Thanks a lot m8 :D I totally forgot that one.

http://linustechtips.com/main/topic/334934-unofficial-ltt-beginners-guide/ (by Minibois) and a few things that will make our community interaction more pleasent:
1. FOLLOW your own topics                                                                                2.Try to QUOTE people so we can read through things easier
3.Use
PCPARTPICKER.COM - easy and most importantly approved here        4.Mark your topics SOLVED if they are                                
Don't change a running system

Link to comment
https://linustechtips.com/topic/485844-even-or-uneven-number/#findComment-6514407
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×