myeclipse运行出错

[复制链接]
查看11 | 回复1 | 2008-12-7 20:20:16 | 显示全部楼层 |阅读模式
以下是我的代码:
public class Ji {

public static void main(String []args){

try{

int a=1%0;

System.out.println("1111111111");

}catch(Exception e){

e.printStackTrace();

System.out.println("1111111111");



}

System.out.println("1111111111");

}
}
可是运行的结果有时对有时错:
运行结果1:
java.lang.ArithmeticException: / by zero
at main.Ji.main(Ji.java:6)
1111111111
1111111111
运行结果2:
1111111111
1111111111
java.lang.ArithmeticException: / by zero
at main.Ji.main(Ji.java:6)
还有好些运行的情况,我知道第一种是正确的。可是为什么会运行出第二种情况呢?

回复

使用道具 举报

千问 | 2008-12-7 20:20:16 | 显示全部楼层
int a=1%0???能用0么??%的语法要求和/的是一样的,你那样做是产生了异常的,而且是不确定性异常!!...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行