This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Mod(%) operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Mod(%) operator" Watch "Mod(%) operator" New topic
Author

Mod(%) operator

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477



When taking y value as 0 in i1,it gives y1 as true.(0==0).When taking y value as 1 in i1,1 mod 2====>1/2=quotient 0.5 and reminder 0.that way I had taken.(calculator return quotient value 0.5.but compiler return quotient value 0.0 and remainder 0.).

I know that mod operator will give remainder part only.But when I take 1%2 working,I always take 0 as the remainder and 0.5 as the quotient.How comw the 1%2 value is quotient 0.0 and remainder 0?
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Because they are integer values, not floating point values.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
. . . because you are using integer division, which loses its remainder.does not produce a double result. It is integer division which produces an integer result and it is then cast to a double.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Posted by Rusty Shackleford
Because they are integer values, not floating point values.
Snap.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Because it's not the mod (or modulus) operator nor does it behave like the modulus operator (which Java does not have).

It's the remainder operator, which is described in the JLS. The rest is explanatory from that point on.


Tony Morris
Java Q&A (FAQ, Trivia)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mod(%) operator
 
Similar Threads
SoDuko puzzle
Base Conversions
XOR operation and GCD calculation
Negative Zero's
Preincrement used in an expression