第三章单元测试
如何更改break语句使退出inner和middle循环,继续外循环的下一轮?
outer: for (int x = 0; x < 3; x++) {
middle: for (int y = 0; y < 3; y++) {
inner: for (int z = 0; z < 3; z++) {
if (arr(x, y, z) == targetValue)
break;
}
}
}
以下程序的输出结果为?
public class Test {
public static void main(String args[]) {
for ( int k = 0; k < 3; k++)
System.out.print("k");
}
}
以下代码的调试结果为?
1: public class Q10
2: {
3: public static void main(String[] args)
4: {
5: int i = 10;
6: int j = 10;
7: boolean b = false;
8:
9: if( b = i == j)
10: System.out.println("True");
11: else
12: System.out.println("False");
13: }
14: }
以下代码的调试结果为?
public class test {
public static void main(String args[]) {
int i = 1;
do {
i--;
} while (i > 2);
System.out.println(i);
}
}
下面的代码段执行之后count的值是什么?
int count = 0;
for (int i = 1; i < 4; i++) {
count += i;
}
System.out.println(count);
以下程序的运行结果为:
1. public class Conditional {
2. public static void main(String args [] ) {
3. int x = 4;
4. System.out.println( "value is " +
5. ((x > 4) ? 99.99 : 9));
6. }
7. }
下列程序的运行结果?
public class Test {
public static void main(String a[]) {
int x=3,y=4,z=5;
if (x>3) {
if (y<2)
System.out.println("show one");
else
System.out.println("show two");
}
else {
if (z>4)
System.out.println("show three");
else
System.out.println("show four");
}
}
}
以下程序调试结果
public class test {
public static void main(String args[]) {
int i=1, j=3;
while (j>0) {
j--;
i++;
}
System.out.println(i);
}
}
在switch(expression)语句中,expression的数据类型不能是?
假设a是int类型变量,并初始化为1,则下列哪个为合法的条件语句?
A: continue; B:break inner; C:break middle; D:break outer;
答案:break middle;
A:012 B:0123 C:kkk D:k
A:输出 :False B:在第9行出现编译错误 C:输出 :True D:在第9行出现运行异常
A:0 B:-1 C:1 D:2
A:6 B:1 C:10 D:4
A:输出:value is 99.99 B:在第5行出现编译错误 C:输出: value is 9 D:输出: value is 9.0
A:show two B:show four C: show three D:show one
A:4 B:2 C:0 D:3
A:double B:char C:boolean D:byte
A:if (a) { } B:if (a=2) { } C: if (a<3) { } D: if (true) { }