using System;
using System.Collections.Generic;
using System.Linq;
class MainClass {
public static void Main() {
Console.WriteLine("Hello World!");
string str = "dad";
checkPalindrome(str);
if(checkPalindrome_2(str))
Console.WriteLine("Palindrome from 2nd method");
else
Console.WriteLine("Not a Palindrome from 2nd method");
}
private static void checkPalindrome(string str)
{
bool flag = false;
for (int i = 0, j = str.Length - 1; i < str.Length / 2; i++, j--)
{
if (str[i] != str[j])
{
flag = false;
break;
}
else
flag = true;
}
if (flag)
{
Console.WriteLine("Palindrome");
}
else
Console.WriteLine("Not Palindrome");
}
private static bool checkPalindrome_2(string myString)
{
int length = myString.Length;
for (int i = 0; i < length / 2; i++)
{
if (myString[i] != myString[length - i - 1])
return false;
}
return true;
}
}