网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

阅读下列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";}

}

}


参考答案

更多 “ 阅读下列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) throwsDivideByZeroException {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";}}} ” 相关考题
考题 阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】StringEditor类的功能是:已知一个字符串,返回将字符串中的非字母字符都删除后的字符串。public (1) {public static String removeNonLetters( (2) ){StringBuffer aBuffer=(3);char aCharacter;for(int i=0; i<original.length();i++){aCharacter=(4);if(Character.isLetter(aCharacter))aBuffer.append( (5) );}return new String(aBuffer);}}public class StringEditorTester{public static void main(String args[]){String riginal="Hi!, My Name is Mark, 234I think you are my classmate?!!";System.out.println(StringEditor.removeNonLetters(original));}}

考题 阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

考题 阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序实现十进制向其它进制的转换。[Java程序]ClasS Node{int data;Node next;}class Transform{private Node top;public void print(){Node p;while(top!=null){P=top;if(P.data>9)System.out.print((char)(P.data+55));elseSystem.out.print(p.data);top=p.next;}}public void Trans(int d,int i){//d为数字;i为进制int m;(1) n=false;Node p;while(d>0){(2);d=d/i;p=new Node();if( (3) ){p.data=m;(4);top=P;n=true;}else{p.data=m;(5);top=P;}}}}

考题 阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

考题 阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是计算x和y的最小公倍数。[函数2.1]main(){ int m,n,d,r;seanf("%d %d",m,n);if(m<n) {r=m;m=n;n=r;}(1);while (d%n! =0) (2);printf("%d\n",d);}[函数2.2说明]下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。[函数2.2]include <stdio.h>main(){ char c,preChar='\0';c = getchar();while(c! = '.'){if((3)) putchar(c);else if(preChar! =' ') putchar(c);(4);c=(5);}}

考题 ●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

考题 试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

考题 阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。 【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

考题 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。

考题 阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种 类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。