• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does 0 / 5 give you any exception?
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:Does 0 / 5 give you any exception?


Sorry my mistake.. i was thinking of 5/0 !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic