对于C#中的以下代码,我的数组输出为 " 12152288"而不是它们之间的空格。我该怎么做才能解决这个问题? Here is the Output error I get.这是代码。
static void Main()
{
int[] numbers = {12, 15, 22, 88};
int x;
double average;
double total = 0;
Console.Write("\nThe numbers are...");
for(x = 0; x < numbers.Length; ++x)
Write("{0}", numbers[x]);
Console.WriteLine();
for(x = 0; x < numbers.Length; ++x)
{
total = total + numbers[x];
}
average = total / numbers.Length;
Console.Write("The average is {0}", average);
}
答案 0 :(得分:2)
更改此行:
Write("{0}", numbers[x]);
对此:
Console.Write("{0} ", numbers[x]);