试题查看

首页 > 软件水平考试 > 试题查看
【分析解答题】

【说明】本程序实现功能:读入两个整数,第1个数除以第2个数,声明当除数为零时抛出异常类DivideByZeroException。public classDivideByZeroException{{U}} (1) {{/U}}{ publicDivideByZeroException ( ) { super("Attcmpted to divide by zero"); } }import jav

A、io. *;public classExample { private static int quotient(int numerator, in)\”}t denominator) throwsDivideByZeroException {if (denominator==0) throw{{U}} (2) {{/U}};return(numerator / denominator); } public static void main(String args[]) {int number1=0, number2=0, result0;try{ System.out.print1n("Enter the first number:"); number1 = Integer. valueOf(KeyboarD、getString()).intValue(); System.out.print1n("Enter the second number:"); number2 = Integer. Va1ueOf(KeyboarD、getString()).intValue(); result = quotient(number1,number2);}catch (NumberFormatException e) { System.out.print1n("Invalid integer entered!"); System. exit(-1);}catch ({{U}} (3) {{/U}}) { System.out.print1n(e.to String()); System.exit(-1);}Systcm.out.pfint1n(number1 + "/" + number2 + "=" + result);}}其中, Keyboard类的声明为:import jav
A、io.*; public class Keyboard{ staticBufferedReader inputStream ={{U}} (4) {{/U}} (new InputStreamReader(System.in)); public static int getInteger() {try(return (Intoger.valueOf(inputStream.readLine().trim()).intValue());} catchException e) { e.printStackTrace(); return 0;} } public static String getString() { try{ return (inputStream.readLine()); } catch ({{U}} (5) {{/U}}) { return "0";} }}
查看答案解析

参考答案:

正在加载...

答案解析

正在加载...

根据网考网移动考试中心的统计,该试题:

0%的考友选择了A选项

0%的考友选择了B选项

0%的考友选择了C选项

0%的考友选择了D选项

你可能感兴趣的试题

阅读下列说明以及图示(如图1所示),回答问题1~3。【说明】某大学准备开发一个学阅读下列说明,回答问题1~问题4。【说明】某超市的销售业务由一个销售业务管理系统阅读下列说明以及图示(如图1所示),回答问题1~3。【说明】某大学准备开发一个学阅读下列说明,回答问题1~问题4。【说明】某超市的销售业务由一个销售业务管理系统阅读以下说明和流程图,回答问题1至问题3,将解答写在对应栏内。【说明】(1)流程阅读以下说明,回答问题1至问题3,将解答写在对应栏内。【说明】有如下关系数据库: