目的:将字串"I am  a  programmer"完全反转为"remmargorp   a  ma I"。

方法一:

        private static void reverse()
        {
            string str = "I am  a   programmer";

            for (int i = str.Length -1; i >=0; i--)
            {
                Console.Write(str[i]);
            }

            Console.WriteLine();
        }

方法二:

        private static void reverse()
        {
            string str = "I am  a   programmer";
            char[] arr = new char[str.Length];

            for (int i = 0; i < str.Length; i++)
            {
                arr[i] = str[i];
            }

            Array.Reverse(arr);

            for (int j = 0; j < arr.Length; j++)
            {
                Console.Write(arr[j]);
            }

            Console.WriteLine();
        }

 

相关文章:

  • 2021-07-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-08-15
相关资源
相似解决方案