【发布时间】:2016-07-06 10:15:17
【问题描述】:
我的问题是如何以相反的顺序输出数组中的东西 由两件事分组,仅诉诸while循环 (即没有for循环和Reverse方法等)
我知道第二个while循环不正确,但我不知道如何修改它。
提前感谢您的建议。
Console.WriteLine("Please type four things.");
const int MAX_SIZE = 4;
string[] things = new string[MAX_SIZE];
int i = 0;
while (i < MAX_SIZE)
{
Console.WriteLine("Please type the things.");
things[i] = Console.ReadLine();
i++;
}
i = 0;
while (i < MAX_SIZE)
{
Console.Write(things[i] + ", ");
i--;
}
【问题讨论】:
-
澄清:你有一个数组 [1, 2, 3, 4, 5, 6]。您想以下一种方式输出它: (6, 5), (4, 3), (2, 1) 使用单个 while 循环。对吗?
-
这是正确的,我应该成对输出,用逗号分隔。
标签: c# arrays while-loop