try {
//一些會拋出異常的方法
} catch (Exception e) {
//處理該異常的代碼塊
} finally {
//最終將要執行的代碼塊
}
多重catch的時候,要由小到大,可以理解為作用域大的異常包裹住作用域小的異常,比如:
try{}
catch(MismatchException e){}
catch(){}
catch(Exception e){}
//一些會拋出異常的方法
} catch (Exception e) {
//處理該異常的代碼塊
} finally {
//最終將要執行的代碼塊
}
多重catch的時候,要由小到大,可以理解為作用域大的異常包裹住作用域小的異常,比如:
try{}
catch(MismatchException e){}
catch(){}
catch(Exception e){}
2018-07-04
Exception分為檢查異常和非檢查異常
非檢查異常:RuntimeException分為四種,如下:
NullPointerException、ArrayIndexOutOfBoundsException、ClassCastException、ArithmeticException
非檢查異常:RuntimeException分為四種,如下:
NullPointerException、ArrayIndexOutOfBoundsException、ClassCastException、ArithmeticException
2018-07-04
我寫的代碼可以參考 哦http://www.xianlaiwan.cn/article/40212
2018-07-01
for(int index = str.length()-3;index>0;index-=3){
str.insert(index,",");
}
str.insert(index,",");
}
2018-06-20
int[] nums =new int[10];
//通過循環給數組賦值
for (int i = 0; i < nums.length; i++) {
// 產生10以內的隨機數
int x =(int)(Math.random()*10);
nums[i] = x;// 為元素賦值
}
// 使用foreach循環輸出數組中的元素
for (int num:nums ) {
//通過循環給數組賦值
for (int i = 0; i < nums.length; i++) {
// 產生10以內的隨機數
int x =(int)(Math.random()*10);
nums[i] = x;// 為元素賦值
}
// 使用foreach循環輸出數組中的元素
for (int num:nums ) {
2018-06-14