aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why does (0 % n) not generate an arithmetic exceptoin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why does (0 % n) not generate an arithmetic exceptoin" Watch "Why does (0 % n) not generate an arithmetic exceptoin" New topic
Author

Why does (0 % n) not generate an arithmetic exceptoin

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430


The % operator (remainder/mod operator) return the remainder of the expression by dividing the first number with the second number.
If the first number is 0 (e.g. 0 % 5) the result is always 0. Why does this not return an ArithmeticException?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Does 0 / 5 give you any exception?


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Ankit Garg wrote:Does 0 / 5 give you any exception?


Sorry my mistake.. i was thinking of 5/0 !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does (0 % n) not generate an arithmetic exceptoin