如何在“行"中打印答案? [英] How to print the answers in the "row"?

查看:84
本文介绍了如何在“行"中打印答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从以下代码中将我的答案打印在另一行的下面.喜欢
输出
磁盘:1 2 3 4 5
移动:1 2 7 15 31
有人可以帮我吗?

I am trying to print my answer in one row below another from the following codes. Like
Output
disk: 1 2 3 4 5
move: 1 2 7 15 31
Can someone help me out?

{
    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);

        }

    }
}

推荐答案

请参阅: http://msdn.microsoft.com/zh-CN/library/txafckwd.aspx [ ^ ]


格式项语法
-------------------------------------------------- ------------------------------
每个格式项都采用以下形式,并且由以下组件组成:
{ index[,alignment][:formatString]}
需要匹配的花括号("{"和}").



对齐组件
-------------------------------------------------- ------------------------------
可选的对齐方式组件是一个带符号的整数,指示首选的格式化字段宽度.如果alignment的值小于格式化字符串的长度,则忽略对齐方式,并将格式化字符串的长度用作字段宽度.如果对齐方式为正,则该字段中的格式化数据为右对齐,如果对齐方式为负,则该字段中的格式数据为左对齐.如果需要填充,则使用空格.如果指定了对齐方式,则必须使用逗号.
See: http://msdn.microsoft.com/en-us/library/txafckwd.aspx[^]


Format Item Syntax
--------------------------------------------------------------------------------
Each format item takes the following form and consists of the following components:
{ index[,alignment][:formatString]}
The matching braces ("{" and "}") are required.



Alignment Component
--------------------------------------------------------------------------------
The optional alignment component is a signed integer indicating the preferred formatted field width. If the value of alignment is less than the length of the formatted string, alignment is ignored and the length of the formatted string is used as the field width. The formatted data in the field is right-aligned if alignment is positive and left-aligned if alignment is negative. If padding is necessary, white space is used. The comma is required if alignment is specified.


这篇关于如何在“行"中打印答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆