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
我写的代码可以参考 哦https://www.imooc.com/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