Zero division java integer vs double -
this question has answer here:
- why 1/0 give error 1/0.0 returns “inf”? 4 answers
double doubleresult = 1d/0d; system.out.println(doubleresult); int intresult = 1/0; system.out.println(intresult);
the output is:
infinity exception in thread "main" java.lang.arithmeticexception: / 0
why double 0 division returns infinity , int 0 division throws exception?
this principally due fact double
type (which in java ieee754 64 bit double precision type) has representation infinity, whereas int
type not.
note double doubleresult = 1 / 0;
still cause exception thrown: type of variable result assigned not relevant.
Comments
Post a Comment