3、 在main方法中要调用test(2)方法输出运行时异常,先要创建一个对象实例ChainTest ct = new ChainTest();因为调用ct.test(2)方法中最终打印输出的是一个运行时异常,这里依然需要使用try…catch…语句进行处理包围,catch语句块捕获Exception e异常,再调用e.printStackTrace()方法打印输出这个捕获的运行时异常;
2016-05-31
2、 test(2)方法中要调用test(1)方法,但是因为test(1)方法中抛出了一个喝大了异常,所以test(2)方法就需要使用try…catch…语句进行处理,根据说的需求,需要把喝大了异常转变为一个运行时异常输出。就需要在catch语句块进行转变。第一步:和创建对象实例类似,先要创建一个运行时异常的对象实例,调用运行时异常的含参构造器,输入“司机一滴酒,亲人两行泪”, 调用运行时异常的newExc.inintcause(e)方法把喝大了异常传入运行时异常,最后抛出运行时异常throw newExc
2016-05-31
1、test(1)thows DrunkException先声明将要抛出这种喝大了异常, 声明以后就开始抛出这个喝大了异常,throw new DrunkException(“喝酒别开车!”),并且这里调用喝大了异常的含参构造方法,输入了(“喝酒别开车”)这个参数
2016-05-31
不过 查了官方api, indexOf的解释
int indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character.
求解释啊。。。
int indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character.
求解释啊。。。
2016-05-30
我还抄笔记呢。。。
第一个indexOf方法参数类型写了int,当时就蒙了
看评论果然很多挑错的啊,,
第一个indexOf方法参数类型写了int,当时就蒙了
看评论果然很多挑错的啊,,
2016-05-30
List<Integer>list = new ArrayList<Integer>();
Integer k;
for(int i = 0;i<3;i++){
do{
k = ran.nextInt(1000);
}while(list.contains(k));
list.add(k);
}
studentList.add(new student(list.get(0)+"", "Mike"));
Integer k;
for(int i = 0;i<3;i++){
do{
k = ran.nextInt(1000);
}while(list.contains(k));
list.add(k);
}
studentList.add(new student(list.get(0)+"", "Mike"));
2016-05-29
http://www.imooc.com/opus/resource?opus_id=2963自己写的,感觉还有好多不足,希望大家多多指出,小白一枚,共同进步
2016-05-29
这里的HashMap对象student里的key是ID,value是一个Student对象,Student对象也有ID属性,让人容易混淆。
还有判断有没有包含学生用containsKey(ID)就行了,用get(ID),然后判断是否为null不合理吧
还有判断有没有包含学生用containsKey(ID)就行了,用get(ID),然后判断是否为null不合理吧
2016-05-29