【发布时间】:2015-05-08 09:15:22
【问题描述】:
我正在尝试使用ArrayOutOfBoundException 打印System.out.println 语句,但我不太确定如何执行此操作。
这是我到目前为止所做的:
public class Ex4
{
public static void main(String[] args) {
String text= "";
if ( args.length <= 3 ) {
for (int i=0; i<args.length-1; i++) {
text = text + args[i];
}
System.out.println(text);
}
else if( args.length > 3 ) {
throw new ArrayIndexOutOfBoundsException("Out of Bounds Exc. Size is 4 or more");
}
}
}
【问题讨论】:
-
你想达到什么目的?
-
如果你想调用
System.out.println,就这样做 - 你为什么要抛出异常呢? -
这个问题来自我过去的一篇试卷,它要求使用该例外来专门打印声明,否则我会做你提到的。谢谢
-
这对我来说似乎是一个荒谬的问题。我建议你和你的导师(或其他任何人)提出这个问题,以检查你将参加的任何考试是否可能包含这些奇怪的东西。
标签: java oop exception indexoutofboundsexception