题目
public class Ex3{
int x;
public static void main(String ar[])throws Exception{
int y=0;
Ex3 c=new Ex3();
try{
y=3/c.x;
y=y+1;}catch(Exception e){
System.out.println("errors occur!");
System.out.println("getMessage="+e.getMessage());
System.out.println("toString="+e.toString());}
System.out.println("program ends ok");
System.out.println("the y is:"+y);
}
}
注释一下每行,不太懂try catch的用法
int x;
public static void main(String ar[])throws Exception{
int y=0;
Ex3 c=new Ex3();
try{
y=3/c.x;
y=y+1;}catch(Exception e){
System.out.println("errors occur!");
System.out.println("getMessage="+e.getMessage());
System.out.println("toString="+e.toString());}
System.out.println("program ends ok");
System.out.println("the y is:"+y);
}
}
注释一下每行,不太懂try catch的用法
提问时间:2021-02-23
答案
public class Ex3{ //类int x; public static void main(String ar[])throws Exception{ //主函数,//throws Exception是遇到异常抛出,如果其他类或函数用到可以用catch捕//捉到int y=0; Ex3 c=new Ex3(); try{ //在t...
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点
- 1求批阅英文作文
- 2已知x的平方-2x=3,求代数式(x-1)的平方+(x+2)(x-2)+(x-3)(x-1)的值
- 3向量OA(3,-4),OB(6,-3)OC=(5-m,-3-y)
- 4一家餐厅有40张这样的桌子,按照上图方式每5张桌子拼成1张大桌子,则40张桌子可拼成8张大桌子,共可坐多少
- 5已知a,b都是锐角,且3sin2a+2sin2b=1,3sin2a-2sin2b=0,则a+2b=?
- 6运用修辞手法,写一段描写雨景的话
- 7王湾在《次北固山下》一诗中描写了时序交替中的景物,并暗示时光的流逝,蕴含自然理趣的诗句是:
- 8be动词可以与those缩写吗
- 9一起走过的日子 作文 600子
- 10科学家的话,有矛盾