题目
单项选择题
Analyze the code snippet below and identify the output produced on the Listbox lstOutput. int i, j=0; for (i = 20; i >= 10; i-=2) { j = 2; while (i % j == 2) { j++; } lstOutput.Items.Add (i.ToString() + " " + j.ToString()); }
选项
A.18 2 16 2 14 2 12 2
B.16 2 14 2 12 2 10 2
C.16 2 14 3 12 4 10 5
D.18 2 16 3 14 4 12 5

查看解析
标准答案
Please login to view
思路分析
We need to analyze the code and each option step by step to understand what would be appended to lstOutput.
Option 1: '18 2 16 2 14 2 12 2'
- The outer loop starts with i = 20 and decrements by 2 down to 10, so i takes values 20, 18, 16, 14, 12, 10 in that order.
- Inside the loop, j is initialized to 2. The inner while loop runs while (i % j == 2). For j = 2, i % 2 is 0 for every even i, so i % j == 2 is false right away and the inner loop body never executes. Therefore j stays 2 for every iteration of the outer loop.
- E......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
Match each loop definition with how many iterations it’ll run for. 1: for k=1:2:10 2: for k=[3,7,10] 3: while 4<pi 4: for k=linspace(1,10,10)
Which of the following pseudocode statements represents a repetition statement?
Which of the following is a drawback of while loops?
For loops are more adaptable than while loops.
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!