![[填空题] 请阅读下列程序代码,然后将程序的执行结果补充完整。程序代码:Public class throwsExceptionstatic voidProc(intsel)throw,第1张 [填空题] 请阅读下列程序代码,然后将程序的执行结果补充完整。程序代码:Public class throwsExceptionstatic voidProc(intsel)throw,第1张](/aiimages/%5B%E5%A1%AB%E7%A9%BA%E9%A2%98%5D+%E8%AF%B7%E9%98%85%E8%AF%BB%E4%B8%8B%E5%88%97%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81%EF%BC%8C%E7%84%B6%E5%90%8E%E5%B0%86%E7%A8%8B%E5%BA%8F%E7%9A%84%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C%E8%A1%A5%E5%85%85%E5%AE%8C%E6%95%B4%E3%80%82%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81%EF%BC%9APublic+class+throwsExceptionstatic+voidProc%28intsel%29throw.png)
[填空题] 请阅读下列程序代码,然后将程序的执行结果补充完整。
程序代码:
Public class throwsException
static voidProc(intsel)
throws ArtthmeticExcepdon,AITaylndexOut of BoundsException
System.out println("In SimatiOn"+Sel);
if(sel==0)
System.out.println("noExceptioncallght");
return;
elseif(sel==1)
intiArray[]=newint[4];
i Array[1]=3;
public static void main(Stringargs[])
tfy
Proc(0);
Proc(1);
catch(ArraylndexOutOfBoundsExceptione)
System.out.println("Catch"+e);
flnally
Systern.out.println("inProcfinally");
执行结果:
In Situattion 0
no Exceptioncaught
inProcfinally
正确答案:In SituationI
参考解析:本题考查考生阅读Java程序的能力。题日程序看似复杂,但流程时常简单。程序的public类是 throwsException,类中定义了Proc(intsel)方法。程序入口是main()方法,使用try-catch-finally来捕获ArithmeticException和Array lndexOutOfBounds-Exception异常,这两个异常是关于算术异常或数组索引越界的异常。执行Proc(0)时,输出InSituation0和noExceptioncaught两条信息;执行Proc(1)时,输出InSituationl和inProcfmally两条信息。整个程序并未发生异常。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)