Write code for palindrome?

Answers were Sorted based on User's Feedback



Write code for palindrome?..

Answer / sathish

private bool CheckPalindrome(string myString)
{
string strrevs="";
foreach char c in myString
{
strrevs= c + strrevs;
}

if (strrevs==myString)

return true;
else
return false;
}

Is This Answer Correct ?    29 Yes 9 No

Write code for palindrome?..

Answer / rajender

private bool CheckPalindrome(string myString)

{

int First;

int Second;

First = 0;

Second = myString.Length - 1;

while (First < Second)

{

if(myString.Substring(First,1) == myString.Substring
(Second,1))

{

First ++;

Second --;

}else{

return false;

}

}

return true;

}

Is This Answer Correct ?    17 Yes 6 No

Write code for palindrome?..

Answer / dextr316

Dim inputvalue As String = TextBox1.Text
Dim reversevalue As String = StrReverse(inputvalue)
If (inputvalue = reversevalue) Then
MsgBox("Palindrome")
Else
MsgBox("Not a Palindrome")
End If
End Sub

Is This Answer Correct ?    11 Yes 2 No

Write code for palindrome?..

Answer / kautilya

bool CheckPalindrom(string MyString)
{
string strChar1 = "";
string strChar2 = "";
for (int i = 0; i < ((MyString.Length - 1) / 2);
i++)
{
strChar1 = MyString.Substring(i, 1);
strChar2 = MyString.Substring((MyString.Length -
(i+1)), 1);
if (strChar1 != strChar2)
return false;
}
return true;
}

Is This Answer Correct ?    11 Yes 7 No

Write code for palindrome?..

Answer / irfan khan

string s1="";
string s2="";
int len=s1.length;
for(int i=0;i<len-1;i++)
{
s2=s1.substring[i]+s2;
console.writeline(s2);
}
if(strcmp(s1,s2)==0)
{
console.writeline("given sting is palindrome");
}
else
console.writeline("not palindrome");

Is This Answer Correct ?    12 Yes 8 No

Write code for palindrome?..

Answer / manindra agrawal

using System;
using System.Collections.Generic;
using System.Text;


class plaindrome
{
public static void Main()
{

string str1="";
int n,i=0;
int status=0;
System.Console.WriteLine("Enter the value...");

str1=Console.ReadLine(); // accept the value from the user
int len;
len=str1.Length; //calculating Lenght of the string
n=len;
while(i<n/2)
{

if(str1[i]==str1[n-1])
{
status=1;
i++;
n--;
}

else
status=0;
break;
}

if(status==1)
System.Console.WriteLine("Given string is plaindrom");

else
System.Console.WriteLine("Given String is not Plaindrome");
}

}

Is This Answer Correct ?    7 Yes 5 No

Write code for palindrome?..

Answer / karthi sanjivi

class Program
{
static void Main()
{
Console.WriteLine("Please Enter Value : ");
string _strValue = Console.ReadLine();
bool res = CheckPalindrome(_strValue);
Console.WriteLine(res);
Console.ReadLine();
}

private static bool CheckPalindrome(string _strValue)
{
string _strTempValue = _strValue;
string _strRevValue = string.Empty;
char[] ch = _strTempValue.ToCharArray();
Array.Reverse(ch);
_strRevValue = new string(ch);
return (_strRevValue == _strValue);
}
}

Is This Answer Correct ?    7 Yes 6 No

Write code for palindrome?..

Answer / sayan

Private Sub btnAnswer_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnevaluate.Click
Dim Input As String

If IsPalindrome(Input) Then
txtAnswer.Text = "True"
Else
txtAnswer.Text = "False"

End If



End Sub
Function IsPalindrome(ByVal Input As String) As Boolean

Dim Front As Integer
Dim Back As Integer
Dim Middle As Integer
Dim nPalindrome As Boolean

IsPalindrome = False
nPalindrome = True


Back = Input
Middle = Back / 2
Front = 1
If (Back < 1) Then
Exit Function
End If

Do While (Front <> Back And Front <= Middle)
If (Mid(Input, Front, 1) <> Mid(Input, Back, 1)) Then
nPalindrome = False
Exit Do
End If
Back = Back - 1
Front = Front + 1
Loop
IsPalindrome = nPalindrome
Exit Function

End Function
End Class

Is This Answer Correct ?    7 Yes 6 No

Write code for palindrome?..

Answer / dadi

static void checkPalindrome()
{
Console.WriteLine("please enter a string");
string str = Console.ReadLine();
bool isPalindrome = true;
int count = str.Length;
for (int i = 0; i < count / 2; i++)
{
if (str[i] != str[count - i - 1])
{//check char[0]==char[n-1], char[1]== char[n-2] and so on......
isPalindrome = false;
break;
}
}
Console.WriteLine("entered string {0} is {1} palindrome", str, (isPalindrome) ? "a" : "not a");
Console.Read();
}

Is This Answer Correct ?    2 Yes 1 No

Write code for palindrome?..

Answer / bikas pandey

using System;
namespace PalindromeChecker
{
class Palindrome
{
public static void Main(strin[] args)
{
string ename="anna";
Char[] array=ename.ToCharArray();
Array.Reverse(array);
String reversename=new String(array);
if(ename==reversename)
{
Console.WriteLine("It's A Palindrome");
}
else
{
Console.WriteLIne("It's Not A Palindrome");
}
Console.ReadLine();
}
}
}

Is This Answer Correct ?    11 Yes 11 No

Post New Answer

More C Sharp Interview Questions

what are the differences b/w structure and class?

10 Answers  


What is hiding in CSharp ?

1 Answers  


In which way a two-dimensional array declared in C#?

0 Answers   Siebel,


In languages without exception-handling facilities, we could send an error-handling procedure as a parameter to each procedure that can detect errors that must be handled. What disadvantages are there to this method?

0 Answers   HCL,


What are the Types of optimization and name a few and how do u do?

0 Answers   BirlaSoft,






How can we Achieve Late binding in C#.Can any give one example.

5 Answers   Value Labs,


What are the basic string operations? Explain.

0 Answers  


What is short in c#?

0 Answers  


What is the Difference between class and abstract class?

2 Answers  


How does c# achieve polymorphism?

0 Answers  


Why extension method is static?

0 Answers  


What debugging tools come with the .NET ssSDK?

0 Answers   Siebel,


Categories