Why does integer division by zero 1/0 give error but floating point 1/0.0 returns “Inf”?

前端 未结 5 774
别跟我提以往
别跟我提以往 2020-11-29 10:12

I\'m just curious about this:

When evaluating 1/0 in Java, the following exception occurs:

Exception in thread \"main\" java.la

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 10:39

    That's because integers don't have values for +/-Inf, NaN, and don't allow division by 0, while floats do have those special values.

提交回复
热议问题