This week's book giveaway is in the Agile forum.We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# is my understanding of the remainder operator correct?

James Elsey
Ranch Hand
Posts: 228
I'm reading the operators chapter in the SCJP book and just want to confirm that my understanding of this operator is correct.

Means, 3 can fit into 10 3 times, and we are left with 1. therefore y will be 1

z = 2 because 4 fits into 10 twice, and leaves a remainder of 2?

I couldn't find a better way of explaining it, but is this correct?

fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
you got it.

Rob Spoor
Sheriff
Posts: 21095
85
But take care when using negative numbers. Is -10 % 4 2, or is it -2? And what about 10 % -4 and -10 % -4? (Hint: try it out)