判断字符串是否为”回文“

来源:互联网 发布:glibc malloc源码 编辑:程序博客网 时间:2024/05/02 01:31

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">判断str所指字符串是否是”回文“(即顺度和逆读是相同的字符)</span>

使用C#编写结果如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication2._2{    class Program    {        static void Main(string[] args)        {            String str = "";            Console.WriteLine("请输入一个字符串: ");            str = Console.ReadLine();            if (judge(str))            {                Console.WriteLine("这是一个回文");            }            else Console.WriteLine("这不是回文");            Console.ReadKey();        }     <span style="color:#ff0000;">   static bool judge(String str)        {            bool flag = true;            for (int i = 0; i < str.Length; i++)            {                if (str[i]!=str[str.Length-i-1])                {                    flag = false;                }            }            return flag;        }</span>    }}


0 0
原创粉丝点击