Advertisement
connor12568

Untitled

Nov 19th, 2021
1,343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1.   public static void Main()
  2.   {
  3.    Console.WriteLine(Pali("Was it a car or a cat I saw"));
  4.  
  5.   }
  6.  
  7. public static bool Pali(string input)
  8. {
  9.   string word = input.ToLower();
  10.   string result ="";
  11.   string reverse = "";
  12.   for (int i = 0; i < input.Length; i++)
  13.     {
  14.       if(input[i] != ' ')
  15.       reverse += word[i];
  16.     }
  17.   for(int i = input.Length -1; i >= 0; i--)
  18.     {
  19.       if(input[i] != ' ')
  20.       result += word[i];
  21.     }
  22.   if(reverse == result)
  23.     return true;
  24.     else
  25.     return false;
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement