(9-3)请阅读程序,然后写出程序运行结果。(请注意输出不换行)
public class Demo3 {
public static void main(String[] args) {
int a=9,b=0;
double x=9,y=0;
try {
int c=a/b;
}catch(Exception e1) {
System.out.print("1");
try {
double z=x/y;
}catch(Exception e2) {
System.out.print("2");
}finally {
System.out.print("3");
}
}finally {
System.out.println("4");
}
}
}
public class Demo3 {
public static void main(String[] args) {
int a=9,b=0;
double x=9,y=0;
try {
int c=a/b;
}catch(Exception e1) {
System.out.print("1");
try {
double z=x/y;
}catch(Exception e2) {
System.out.print("2");
}finally {
System.out.print("3");
}
}finally {
System.out.println("4");
}
}
}
举一反三
- 读程序,写出和程序输出格式一致的输出结果。 public class J_Test { public static void mb_method(int i) { try { if(i == 1) throw new Exception(); System.out.print("1"); } catch(Exception ex) { System.out.print("2"); return; } finally { System.out.print("3"); } System.out.print("4"); } public static void main(String[] args) { mb_method(0); mb_method(1); } }
- 下面程序的执行结果是( )。public class Test {public static void main(String[] args) {new Test().test();}public void test(){try{System.out.print("try");}catch(ArrayIndexOutOfBoundsException e){System.out.print("catch1");}catch(Exception e){System.out.print("catch2");}finally{System.out.println("finally");}}} A: try finally B: try catch1 finally C: try catch2 finally D: finally
- 下列程序的运行结果是()。 public class Test public static void main ( String [ ] args ) int count = 0 for( int i = 1 i < 5 i = 2) for( int j = 1 j< = 10 j = 3) count System .out .print (count ) _
- class Demo{ public static void main(String[] args){ int x = 0; try{ x = div(1,2); }catch(Exception e){ System.out.println(e); } System.out.println(x) ; } public static int div(int a,int b){ return a / b ; } }
- 阅读下段代码片段 public static void main(String[] args) { { int a = 1; System.out.print(a); } { int a = 2; System.out.print(a); } int a = 3; System.out.print(a); } 下列选项中,哪一个是程序正确的运行结果