Compilation will fail.
The program prints “0”.
The program prints “3”.
Compilation will succeed but an exception will be thrown at line 3.
第1题:
public static void main(String[]args){Integer i=new Integer(1)+new Integer(2);switch(i){case3:System.out.println("three");break;default:System.out.println("other");break;}}Whatistheresult?()
A.three
B.other
C.Anexceptionisthrownatruntime.
D.Compilationfailsbecauseofanerroronline12.
E.Compilationfailsbecauseofanerroronline13.
F.Compilationfailsbecauseofanerroronline15.
第2题:
阅读下面程序 public class My Val{ public static void main(String args[]){ My Val m=new My Val(); m. amethod(); } public void amethod(){ boolean b[]=new Boolean[5]; } } 程序编译或运行结果是
A.1
B.null
C.
D.编译不能过
第3题:
下列程序段的输出结果是【 】。
public class Test {
void printValue(int m) {
do {
System.out.println("The value is"+m);
}while (--m>10);
}
public static void main (String args[]) {
int i=10;
Test t= new Test();
t.printValue(i);
}
}
第4题:
下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"}, public void fun( double S=0; for(int i=0;i<3;i++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print(“errorl:”+data[i])。 } } } public static void main(string[]args){ try{ test d=new test; fun; }catch(Exception e){ System.out.println("error2") } } }
A.errorl:10.5
B.error2
C.errorl:10.5 error2
D.以上都不对
第5题:
下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); public void fun{ double s=0: for(int i=0;i<3;j++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print("errorl:"+data[i]); } } } public static void main(string[]args){ try{ test d=new test: fun: }catch(Exception e){ System.OUt.println("error2") } } }
A.errorl:10.5
B.error2
C.errorl:10.5 error2
D.以上都不对
第6题:
下列代码的执行结果是public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } public static void main(String args[]){ Test test= new Test(); test. aMethod(); }}
A.编译错误
B.0
C.1
D.运行成功,但不输出
第7题:
在下面程序的下画线处应填入的选项是 public class Test______{ public static void main(String args[]) { Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run() { for(int i=0;i<5;i++) System.out.println("i="+i); } }
A.implements Runnable
B.extends Thread
C.implements Thread
D.extends Runnable
第8题:
下列程序的运行结果是
public class test{
private String[] data={“10”,“10.5”};
public void fun(){
double s=0;
for(int i=0;i<3;i++){
try{
s=s+Integer .parseInt(data[i]);
}catch(Exception e){
System.out.print(“errorl:”+data[i]);
}
}
}
public static void main(String[]args){
try{
testd=new test();
d .fun();
}catch(Exception e){
System.out.printIn(“error2”);
}
}
}
A.errorl:10.5
B.error2
C.errorl:10.5 error2
D.以上都不对
第9题:
下列代码的执行结果是( )。
public class Test{
public int aMethod( ){
static int i=0;
i++;
System.out.println(i):
}
public static void main (String args[]){
Trest test=new Test ( );
test aMethod( ):
}
}
A.编译错误
B.0
C.1
D.运行成功,但不输出
B.
C.
D.
第10题:
设有如下程序
public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();
if(args.length >1、
System.out.println(i);
if(args.length >0)
System.out.println(i -1、;
else
System.out.println(i - 2、;
}
}
运行程序,输入如下命令:
java test 2
则输出为:
A. test
B. test -1
C. 0
D. 1
E. 2