AP计算机教程5-6:中等多选题
0:00
How many stars are output when the following code is executed?
for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) System.out.println("*"); }
外层循环执行5次,内层循环执行5次,一共\(5\times5 = 25\)次。
3
Which of the following code segments will produce the displayed output?
1
22
333
4444
55555
首先排除每个数换行的IV。对于II,第一行不输出
1
。对于III,总共只输出四行。对于V,第一行输出数为零个。1
What is printed as a result of the following code segment?
for (int k = 0; k < 20; k+=2) { if (k % 3 == 1) System.out.println(k + " "); }
注意
k
的范围仅限小于20
的偶数,除三余一的话只剩下4
、10
和16
。5
Which of the following code segments will produce the displayed output?
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
首先排除每个数换行的IV。因为第一行一直显示
1
,可以排除每列输出变化的V。因为第一行输出5个数,而第五行只有1个数,满足这个的内层循环只有I。1
What are the values of var1
and var2
after the following code segment is executed and the while loop finishes?
int var1 = 0; int var2 = 2; while ((var2 != 0) && ((var1 / var2) >= 0)) { var1 = var1 + 1; var2 = var2 - 1; }
由于短路求解,
&&
后接的第二个条件在第一个已经为false
时不会被执行。4
0 条评论