C#中的Streamwriter不会输出

时间:2017-10-10 18:08:36

标签: c# if-statement streamwriter

如果我没有" if(数字%2!= 0)"我的文件将打印出来。 但挑战是只输出奇数。我尝试调试代码,它遍历所有内容并遍历WriteLine。

namespace stairway_to_heaven
{
    class Program
    {
        static void Main(string[] args)
        {
            string datastring = File.OpenText("sizes.txt").ReadToEnd();
            string[] data = datastring.Split('\n');

            StreamWriter sw = new StreamWriter("output.txt");

            for (int i = 0; i < data.Length; i++)
            {
                int number = Convert.ToInt32(data[i]);
                int star = 0;
                if (number % 2 !=0)
                {

                    for (int x = 0; x < number; x++)
                    {
                        string Space = "";
                        string Star = "";
                        int space = number - star;
                        star++;

                        for (int n = 0; n < star; n++)
                        {
                            Star += "*";
                        }
                        for (int y = 1; y < space; y++)
                        {
                            Space += " ";
                        }

                        sw.WriteLine(Space + Star);

                    }

                    sw.WriteLine("");

                }
            }
        }
    }
}

0 个答案:

没有答案