读程序,写出和程序输出格式一致的输出结果。
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 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 ) int count = 0 for( int i = 1 i < 5 i = 2) for( int j = 1 j< = 10 j = 3) count System .out .print (count ) _
- (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 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 m=0; for ( int k=0;k<2;k++) method(m++); System.out.println(m); } public static void method(int m) { System.out.print(m); } }
- 定义类Block和类Demo,运行Demo的输出结果是。 class Block{ {//代码1 System.out.print("1"); } static{//代码2 System.out.print("2"); } {//代码3 System.out.print("3"); } public Block() {//代码4 System.out.print("4"); } static void show() {//代码5 System.out.print("5"); } static {//代码6 System.out.print("6"); } } //定义测试类Demo public class Demo { public static void main(String[] args) { new Block().show(); new Block() } }