河南成教 / 河南理工大学
1[分析题]
试写出下面这个程序的执行结果.
class ExceptionTest {
static String a[] = {"123", "abc", null};
public static void main (String args[]) {
for (int i = 0; i < 3; i ) {
try {
int x = Integer.parseInt(a[i]);
System.out.println( "Result: " x);
}
catch(NullPointerException e) {
System.out.println("error null:");}
catch (NumberFormatException e)
{System.out.println("error:abc" );}
finally{System.out.println ("In " i "th loop
"); }
} //end for
}
}
1[分析题]
试写出下面这个程序的执行结果.
class ExceptionTest {
static String a[] = {"123", "abc", null};
public static void main (String args[]) {
for (int i = 0; i < 3; i ) {
try {
int x = Integer.parseInt(a[i]);
System.out.println( "Result: " x);
}
catch(NullPointerException e) {
System.out.println("error null:");}
catch (NumberFormatException e)
{System.out.println("error:abc" );}
finally{System.out.println ("In " i "th loop
"); }
} //end for
}
}
参考答案:
佳题速递: