举一反三
- 请看下面的程序代码,当 n 为( )值时,程序段将输出字符串 second。 [br][/br] switch(n) { [br][/br] case 0: System .out .println(“first”); [br][/br] case 1: [br][/br] case 2: System .out .println(“second”); break; [br][/br] default: System .out .println(“end”); [br][/br] }(2.0) A: 0 B: 1 C: 2 D: 以上都可以
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }
- 以下程序段的输出结果为 【14】 。int x=0,y=4,z=5;if(x>2)if(y<5)System. out. println("Message one");elseSystem. out . println("Message two");else if(z>5)System. out. println("Message three");elseSystem. out. println("Message four");
- 以下代码段的输出结果为1. int x = 0, y = 4, z = 5;2. if (x > 2) {3. if (y < 5) {4. System. out .println ( "message one" );5. }6. else {7. System.out.println( "message two");8. }9. }10. else if (z > 5) {11. System.out.println("message three");12. }13. else {14. System.out.println( "message four");15. } A: message one B: message two C: message three D: message four
- 下面程序运行将会输出结果( )。try{String[] lines = new String[2];for(int i=0; i<3; i++) System.out.println(lines[i].length());System.out.println(“The End”);}catch(NullPointerException e){System.out.printn(“***********”);}catch(ArrayIndexOutOfBoundsException e){System.out.println(“++++++”)}catch(Exception e){System.out.println(“==========”)}[/i] A: 00++++++ B: ***********++++++========== C: *********** D: 00The End
内容
- 0
【单选题】对于下面代码,正确的Java源程序文件名是( )。 class A { void method1() { System. out .println( "Method1 in class A" ); } } public class B { void method2() { System. out .println( "Method2 in class B" ); } public sta
- 1
以下哪个是Java ArrayList 类的方法? A: add B: println C: import D: System
- 2
调用以下类D和E的main() 方法的输出结果为?class D { public static void main(String[] args) { String s1 = new String("hello"); String s2 = new String("hello"); if (s1.equals(s2)) System.out.println("equal"); else System.out.println("not equal"); }} class E { public static void main(String[] args) { StringBuffer sb1 = new StringBuffer("hello"); StringBuffer sb2 = new StringBuffer("hello"); if (sb1.equals(sb2)) System.out.println("equal"); else System.out.println("not equal"); }} A: D: equal; E: equal B: D: not equal; E: not equal C: D: equal; E: not equal D: D: not equal; E: equal
- 3
阅读下面的代码段,屏幕的输出是什么?public static void main(String[] args) { try{tryThis();return;}catch(IOException x1){ System.out.println("exception 1");return;}catch(Exception x2){System.out.println("exception 2");return;}finally{ System.out.println("finally");} } static void tryThis() throws IOException{ throw new IOException(); } A: ”exception1”后面跟着”finally” B: ” exception2”后面跟着“finally” C: ”exception1” D: ”exception2”
- 4
(9-2)下面程序能够通过编译检查。 public class Demo5 { public static void main(String[] args) { try { System.out.println(3/0); System.out.println("你好"); }catch(Exception e) { e.printStackTrace(); }catch(ArithmeticException e) { e.printStackTrace(); } } }