gpt4 book ai didi

c# - 如何在另一行下方的一行中打印输出?

转载 作者:行者123 更新时间:2023-11-30 22:06:04 25 4
gpt4 key购买 nike

例如,我尝试以下列方式打印输出:
磁盘:1 2 3 4 5
移动:1 3 7 15 31
我该怎么做,有人可以帮我吗?

{
class Program
{
static void Main(string[] args)
{
int n = 2;

for (int j = 1; j <= 5; j++)
Console.WriteLine("disk: {0}", j);

for (int i = 1; i <= 5; i++)
Console.WriteLine("moves: {2:N0}",
n, i,(long)Math.Pow(n, i) - 1);

}

}
}

最佳答案

Console.WriteLine 听起来每次都会写一个新行。如果您不想要这种行为,请使用 Console.Write

Console.Write("Disk:");
for (int j = 1; j <= 5; j++)
Console.Write(" {0}", j);
Console.WriteLine();

Console.Write("Moves:");
for (int i = 1; i <= 5; i++)
Console.Write(" {2:N0}", (long)Math.Pow(n, i) - 1);
Console.WriteLine();

关于c# - 如何在另一行下方的一行中打印输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23900608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com