• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Division & Modulus Operators

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pl.clarify if the following are correct.
1.Integral division by 0 :Runtime Exception
2.Floating point division by 0:Result is Infinity
1.Integral Modulus operation by 0:Runtime Exception
(int i =10;
int result = i % 0
2.Floating point Modulus operation by 0:Result is Nan.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.] Yes, divide by zero throws an ArithmeticException, which is a RuntimeException
2.] Floating point division by zero throws an ArithmeticException, results are infinite
3.] Throws ArithmeticException, divide by zero.
4.] Throws ArithmeticException, result is not a number (NaN).
Here's a test class so you can see exactly this:
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Geetha,
That's about the size of it. Just remember that if you do something like:

You'll still get a RuntimeException because the expression on the right evaluates to an int. So you need to do something like this instead:

Hope this helps
Michael Morris
SCJP2
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!