1.當除數是非0,除法運算完畢,程式繼續執行。
2.當除數是0,程式發生異常,并且除法運算之後的代碼停止運作。因為程式發生異常需要進行處理。
class Demo {
public static void main(String[] args) {
div(2, 0);
System.out.println("over");
}
public static void div(int x, int y) {
//該行代碼的y值可能是0,程式會出現異常并停止
System.out.println(x / y);
System.out.println("除法運算");
}
}
//ArithmeticException
疑問: 出現異常如何處理?