Exception in thread “main“ java.lang.ArithmeticException: / by zero

今天Nick写代码报了如下错误   

------------------------------------------------------------------------------------------------------------------------------

例子: 

public class Demo {
    public static void main(String[] args) {
        int a = 10;
        int b = 0 ;
        System.out.println(a/b);
    }
}

      

      出现这种异常的原因有以下两种,均是除数为0。

     

//情况1:
class a{
    public static void main(String[] args){
        System.out.println(5/0);
    }
}
 
//情况2
class a{
    public static void main(String[] args){
        System.out.println(5%0);
    }
}

      

      Exception in thread "main" java.lang.ArithmeticException: / by zero

---------------------------------------------------------------------------------------------------------------------------

算数异常

by zero 是指报错的原因

除数不能为零

        

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务