Lily P.

asked • 10/30/20

Why wont this code work?

static bool Palindrome (string input)

       {

           bool pal;

           string check = "";

           for (int i = input.Length; i >= 0; i--)

           {

               check = check + input[i];

           }

           if(check == input)

           {

               pal = true;

           }

           else

           {

               pal = false;

           }

           return pal;

       }

       static void Main(string[] args)

       {

           Console.Write("Write a word: ");

           bool palindrome = Palindrome(Console.ReadLine());

           if (palindrome == true)

           {

               Console.WriteLine("Palindrome");

           }

           else

           {

               Console.WriteLine("Not palindrome");

           }

           Console.ReadKey();

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.