Java Bugs with math-int vs Double

Today I noticed something strange. I wrote code that was supposed to make graphs in complex quadrants. Anyway, I typed int i = 1/0;and it won’t compile. When I changed the code to double i = 1.0/0.0;, the code compiled in order. When I ran the code, it threw an error / of 0. I expected this ... But why does it compile fine when using paired rather than integer numbers? I am using the Blue J IDE

+3
source share
1 answer

Dividing the value intby zero will result in ArithmeticException, so the expression 1 / 0is illegal.

The result of dividing the value doubleby zero is infinity or NaN * , so the expression 1.0 / 0.0is legal.


*) See t_over comment for specifics:

+4
source

All Articles