Check if a double is infinite in Java

后端 未结 7 482
深忆病人
深忆病人 2020-12-10 10:22

I\'m making a simple calculator for this homework, and Java is returning \"Infinity\" when divided by 0.

I need to display some error message, when I get infinity. T

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 10:59

    Jacek Kwiecień try this code

    double result;
    try{
        result=4.0/0.0;
    }catch(ArithmeticException e){
    
        System.out.println("Math error "+ e.getMessage())
    }
    

    `

提交回复
热议问题