quote:Originally posted by sharadagarwal
Hello Friends!! I was thinking today for some examples of ArithmeticException other than divide by zero.Can anybody tell me some of such examples?
Maybe I can think of some (try it out and see if they do cast the ArithmeticException you are looking for):
Math.sqrt(-1), square roots of negative numbers,
- You could create your own package for Complex numbers, and it wouldn't even be difficult, I imagine.. (but probably some university somewhere on the web has done that already, and you just need to find it..)
Divide by zero for (int) and (long) typed numbers,
I mention that again because the floating point (float), (double) types return negative infinity for -1.0/0.0, not a number (NaN) for 0.0/0.0 and positive infinity for 1.0/0.0,
besides: my compiler does allow for direct division of an integer by zero (contrary to what Ivor says in the book). Of course this throws an ArithmeticException, just like the example in the book.
- I will write my own 'alternative algebra' package (when I know Java), that handles zero multiplication and division quite differently (0: I can tell you now that I will derive it from the BigDecimal class, my dear friend :0)
What else? Eh... ArithmeticException hmmm...
1 % 0 will throw one of course, but that is effectively the same as zero division
I think I must leave you with those examples
@ chapter 9 (the dolldrums)