首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。 【说明】本程序实现功能:读入两个整数,第1个数除以第2个数,声明当除数为零时抛出异常类DivideByZeroException。 public class DivideByZeroEx
阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。 【说明】本程序实现功能:读入两个整数,第1个数除以第2个数,声明当除数为零时抛出异常类DivideByZeroException。 public class DivideByZeroEx
admin
2009-02-15
48
问题
阅读下列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中捕捉输入输出异常信息。
转载请注明原文地址:https://kaotiyun.com/show/DrDZ777K
本试题收录于:
软件设计师下午应用技术考试题库软考中级分类
0
软件设计师下午应用技术考试
软考中级
相关试题推荐
集成测试关注的问题不包括()。
在软件开发过程中,详细设计的内容不包括()设计。
假设段页式存储管理系统中的地址结构如下图所示,则系统()。
1976年Diffie与Hellman首次公开提出___________的概念与结构,采用两个独立的密钥对数据分别进行加密与解密,且加密过程基于数学函数,从而带来了加密领域的革命性进步。
一条Bug记录应包括__________。①编号②Bug描述③Bug级别④Bug所属模块⑤发现人
某个应用中,需要对输入数据进行排序,输入数据序列基本有序(如输入为1,2,5,3,4,6,8,7)。在这种情况下,采用(40)排序算法最好,时间复杂度为(41)。(41)
某个应用中,需要对输入数据进行排序,输入数据序列基本有序(如输入为1,2,5,3,4,6,8,7)。在这种情况下,采用(40)排序算法最好,时间复杂度为(41)。(40)
以下所示程序控制流程图中有(59)条线性无关的基本路径。
页式存储系统的逻辑地址是由页号和页内地址两部分组成。假定页面的大小为4K,地址变换过程如下图所示,图中逻辑地址用十进制表示。图中有效地址经过变换后,十进制物理地址a应为(18)。
若某计算机采用8位整数补码表示数据,则运算______将产生溢出。A.127+1B.-127-1C.-127+1D.127-1
随机试题
试述实施实质性程序的总体要求。
Areyou(going)downtown(thisafternoon)?Iam(goingtohave)theseletters(mail).
A.清热化湿解毒B.清热凉血解毒C.散寒燥湿化浊D.温中理脾E.温补固涩
小儿易发生肠套叠的主要原因是()。
下列工程项目风险管理工作中,属于风险识别阶段的工作是()。
小规模纳税人购进货物支付的增值税直接计入有关货物的成本。()
一般情况下,在一次训练课中力量练习的顺序是()。
对于全国人民代表大会代表的认识,下列说法正确的是()。
设f″(x)连续,f(x)≠0,则dx=____________.
WithateamoftheresearchersatTokyoNationalUniversity,hesetaboutmeasuringbrainvolumesofathousandpeopleofdiffer
最新回复
(
0
)