1,2,3,4,5,6,7,8用C#把他排列成
1,2,3
1,2,3
1,2请问怎么实现?

解决方案 »

  1.   

    是这样把
    string[] _Value = "1,2,3,4,5,6,7,8".Split(',');            StringBuilder _TextBuilder = new StringBuilder();            int _Count = 0;
                for (int i = 0; i != _Value.Length; i++)
                {
                    if (_Count != 2)
                    {
                        _TextBuilder.Append(_Value[i]);
                        if (i != _Value.Length - 1) _TextBuilder.Append(',');
                        _Count++;
                    }
                    else
                    {
                        _TextBuilder.AppendLine(_Value[i].ToString());
                        _Count = 0;
                    }
                }
                MessageBox.Show(_TextBuilder.ToString());
      

  2.   

                int k = 1;
                for (int i = 0; i < 10; i++)
                {
                    if (k == 4)
                    {
                        Console.WriteLine("");
                        k = 1;
                    }
                    else
                    {
                            Console.Write(k+++" ");
                    }
                }
                Console.ReadLine();
    这样是可以做到吧
      

  3.   

                    String[] mystr = "1,2,3,4,5,6,7,8".Split(',');
                    foreach (string s in mystr)
                    {
                        if (int.Parse(s) % 3 != 0)
                        {                        Console.Write(s.ToString() + ',');
                        }
                        if(int.Parse ( s )% 3 ==0)
                        {
                            Console.WriteLine(s.ToString ());
                        }
                    }
      

  4.   

                int[] myarr = new int[] { 1,2,3,4,5,6,7,8,9};
                int k = 1;
                for (int i = 0; i < myarr.Length+1; i++)
                {
                    if (k == 4)
                    {
                        Console.WriteLine("");
                        k = 1;
                    }
                    else
                    {
                        Console.Write(k++ + "");
                    }
                }
                Console.ReadLine();
    你运行一下吧。我这里可以的。
      

  5.   


     string[] mystr = new string[] { "1", "2", "3", "4", "5", "6", "7", "8" };
                int num = mystr.Length;
                while (num > 0)
                {
                    if (num >= 3)
                    {
                        Console.WriteLine("1,2,3");
                    }
                    else
                    {
                        string temp = "";
                        for (int index = 1; index <= num; index++)
                        {
                            temp += index.ToString() + ",";
                        }
                        temp = temp.Substring(0, temp.Length - 1);
                        Console.WriteLine(temp);
                        
                    }
                    num -= 3;
                }