题目
题目
单项选择题

Consider the given code snippet : int j = 10; do { MessageBox.Show(j); j-= 1; } while (j >=0); Which is the correct way to rewrite the above code?

选项
A.int j;for (j = 10; j >=0 ; j--) MessageBox.Show(j);
B.int j = 10;do while ( j >=0){ MessageBox.Show(j); j-= 1;}
C.int j = 10; while (j > 0){ MessageBox.Show(j); j -= 1; }
D.int j = 10; do{ MessageBox.Show(j);} until (j >=0);
题目图片
查看解析

查看解析

标准答案
Please login to view
思路分析
Examining the transformation from a do-while loop to an equivalent loop construct requires matching both behavior and control flow. Option 1: int j; for (j = 10; j >= 0; j--) MessageBox.Show(j); This option uses a for-loop that initializes j (without explicitly declaring it in the same statement as others), checks the condition j >= 0, and decrements j each iteration. It will execute for j = 10 down to j = 0 inclusive, which matches the origina......Login to view full explanation

登录即可查看完整答案

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

更多留学生实用工具

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