首页 存档 技术 查看内容

程序阅读 | 10 Java异常处理

2018-3-30 13:00 |来自: 互联网 303 0

摘要: ===Tips:点击上方蓝字查看历史消息=== 1.下列程序的运行结果为: 。 public class Test { public static void main(String args) { try { myMethod(); System.out.println("Exception "); } catch (MyE ...

===Tips:点击上方蓝字查看历史消息===


1.下列程序的运行结果为:

public class Test {

public static void main(String args[ ]) {

try {

myMethod();

System.out.println("Exception ");

} catch (MyException me) {

System.out.println(me.getMessage());

System.out.println(me);

} finally {

System.out.println("Over");

}

}

public static void myMethod() throws MyException {

throw new MyException("Exception");

}

}

class MyException extends Exception {

public MyException(String message) {

super(message);

}

public String toString() {

return " Customized exception";

}

}


2.以下程序运行时输入1 2 3 a b c 1 2 3 -1后按回车键,则运行结果为:

public class Test {

public static void main(String args[ ]) {

Scanner scan = new Scanner(System.in);

int i = 0, sum = 0, errNum = 0, totalNum = 0;

while (i

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类

返回顶部