阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】本程序实现功能:读入两个整
阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。
【说明】本程序实现功能:读入两个整数,第1个数除以第2个数,声明当除数为零时抛出异常类DivideByZeroException。
public class DivideByZeroException (1) {
public DivideByZeroException ( ) {
super("Attcmpted to divide by zero");
}
}
import java.io. *;
public class Example {
private static int quotient(int numerator, in)\”}t denominator) throws
DivideByZeroException {
if (denominator==0)
throw (2);
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 ((3)) {
System.out.print1n(e.to String());
System.exit(-1);
}
Systcm.out.pfint1n(number1 + "/" + number2 + "=" + result);
}
}
其中, Keyboard类的声明为:
import java.io.*;
public class Keyboard{
static BufferedReader inputStream =(4)
(new InputStreamReader(System.in));
public static int getInteger() {
try(
return (Intoger.valueOf(inputStream.readLine().trim()).intValue());
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
public static String getString() {
try{
return (inputStream.readLine());
} catch ((5))
{ return "0";}
}
}
(1)extends ArithmeticException (2)new DivideByZeroExeeption() (3)DivideByZeroException e (4)new BufferedReader (5)IOException e 解析:(1)extends ArithmeticException
DivideByZeroException类从ArithmeticException类扩展而来。
(2)new DivideByZeroExeeption()
throw一个DivideByZeroException异常函数,打印错误信息。
(3)DivideByZeroException e
捕捉DivideByZeroExeeption异常信息。
(4)new BufferedReader
动态生成一个BufferedReader对象用于输入。
(5)IOException e
字符串成员函数getString中捕捉输入输出异常信息。
质量为100g的球从1.8m高处落到水平板上,又弹回到1.25m的高度,下落过程中重力对球所做的功 物理 2020-05-20 …
效率低下的SQL语句往往是导致系统性能不佳的主要原因。设有如下优化系统性能的方法:Ⅰ.利用存储过程封 计算机类考试 2020-05-24 …
是你的技算过程)再一次体育测试中,小红在1分钟内连续跳绳120次,每次跳起的平均高度为4厘米,若她 物理 2020-06-24 …
一辆电动自行车的铭牌上给出了如下技术指标:规格后轮驱动直流电机车型26型电动自行车额定输出功率12 物理 2020-06-27 …
“成功v、成功n、成功的adj、成功地adv”英语怎么说就是有点搞混了 英语 2020-07-16 …
用换元法解方程组5x-6y+1=11x+2y+1=1时,可设1x=u,1y+1=v,则原方程组可化为 数学 2020-10-31 …
成就;成绩(n.)宽的(adj.)包括;包含(v.)条件;状况(n.)实现目标;成功(v.)考验;挑 其他 2020-11-06 …
唯物辩证法要求我们要求我们要树立全局观念,选择最佳方案,实现整体的最优目标,这是因为A.没有部分就没 政治 2020-11-24 …
7.successn.成功→v.成功→adj.成功的→adv.成功地8.luckn.幸运;运气→ad 其他 2020-12-15 …
跪求EDA课程设计设计一数字钟电路设计设计要求1、具有时,分,秒,计数显示功能,以24小时循环计时。 其他 2020-12-27 …