0 2 4
0 2 4 5
0 1 2 3 4
Compilation fails.
An exception is thrown at runtime.
第1题:
有以下程序
#include<stdio.h>
main( )
{int a[]={2,3,5,4},i;
for(i=0;i<4;i++)
switch(i%2)
{case 0:switch(a[i]%2)
{case 0:a[i]++;break;
case 1:a[i]--;
}break;
case 1:a[i]=O;
}
for(i=O;i<4;i++)prinff(“%d”,a[i]);prinff(“\n”);
}
程序运行后的输出结果是
A.3 3 4 4
B.2 0 5 0
C.3 0 4 0
D.0 3 0 4
第2题:
int i = 0, j = 5; tp; for (;;) { i++; for(;;) { if (i> --j) { break tp; break tp; } } System.out.println(“i=” +i “,j =”+j); } What is the result?()
第3题:
int i = 0; while (true) { if(i==4) { break; } ++i; } System.out.println(“i=”+i); What is the result?()
第4题:
public class Test { public static void main(String Args[]) { int i =1, j = 0; switch(i) { case 2: j +=6; case 4: j +=1; default: j +=2; case 0: j +=4; } System.out.println(“j =” +j); } } What is the result? ()
第5题:
public class Delta { static boolean foo(char c) { System.out.print(c); return true; } public static void main( String[] argv ) { int i =0; for ( foo(‘A’); foo(‘B’)&&(i<2); foo(‘C’)){ i++ ; foo(‘D’); } } } What is the result?()
第6题:
int i = 1,j = -1; switch (i) { case 0, 1:j = 1; case 2: j = 2; default; j = 0; } System.out.println(“j=”+j); What is the result?()
第7题:
i = 0
i = 3
i = 4
i = 5
Compilation fails.
第8题:
0
2
4
6
9
13
第9题:
i = 1, j = 2
i = 1, j = 1
i = 42, j = 2
i = 42, j = 1
Compilation fails.
第10题:
The code will deadlock.
The code may run with no output.
An exception is thrown at runtime.
The code may run with output “0 6”.
The code may run with output “2 0 6 4‟.
The code may ruin with output “0 2 4 6”.
第11题:
j = -1
j = 0
j = 1
j = 2
Compilation fails.
第12题:
0 1 2 3 4 5
1 2 3 4 5 6
-1 0 1 2 3 4
0 1 2 3 4
第13题:
public class Test { public static void add3 (Integer i) { int val = i.intValue(); val += 3; i = new Integer(val); } public static void main(String args[]) { Integer i = new Integer(0); add3(i); System.out.println(i.intValue()); } } What is the result? ()
第14题:
int i = 0, j = 1; if ((i++ == 1) && (j++ == 2)) { i = 42; } System.out.println(“i = “ + i + “, j = “ + j); What is the result?()
第15题:
class Super { public int i = 0; public Super(String text) { i = 1; } } public class Sub extends Super { public Sub(String text) { i = 2; } public static void main(String args[]) { Sub sub = new Sub(“Hello”); System.out.println(sub.i); } } What is the result?()
第16题:
public static void main(String[] args) { for (int i=0;i<= 10;i++){ if( i>6) break; } System.out.println(i); } What is the result?()
第17题:
int i = 0; for (; i <4; i += 2) { System.out.print(i + “”); } System.out.println(i); What is the result?()
第18题:
class Computation extends Thread { private int num; private boolean isComplete; private int result; public Computation(int num) { this.num = num; } public synchronized void run() { result = num * 2; isComplete = true; notify(); } public synchronized int getResult() { while (!isComplete) { try { wait(); } catch (InterruptedException e) { } } return result; } public static void main(String[] args) { Computation[] computations = new Computation [4]; for (int i = 0; i < computations.length; i++) { computations[i] = new Computation(i); computations[i] .start(); } for (Computation c : computations) System.out.print(c.getResult() +“ “); } } What is the result?()
第19题:
4:4:2:2
4:4:3:2
2:2:1:0
2:2:0:0
2:1:0:0
2:2:1:1
4:3:2:1
第20题:
ABDCBDCB
ABCDABCD
Compilation fails.
An exception is thrown at runtime.
第21题:
0
1
2
Compilation fails.
第22题:
6
7
10
11
Compilation fails.
An exception is thrown at runtime.
第23题:
0
3
Compilation fails.
An exception is thrown at runtime.