题目
题目

Introduction To Object Oriented Programming (CT044-3-1-IOOP-25-RESIT)

单项选择题

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.18 2  16 3  14 4  12 5
C.16 2  14 2  12 2  10 2
D.16 2  14 3  12 4  10 5
题目图片
查看解析

查看解析

标准答案
Please login to view
思路分析
To tackle this question, I’ll step through the code logic and then examine each answer choice in order. First, note the outer for loop: for (i = 20; i >= 10; i -= 2). This initializes i at 20 and decrements by 2 each iteration, continuing as long as i is at least 10. Therefore, i takes the values 20, 18, 16, 14, 12, and 10 in sequence. Next, inside the loop, j is set to 2 on every iteration: j = 2. Then there is a while loop: while (i % j == 2) { j++; }. This loop increments j as long as the remain......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!