Write code for palindrome?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Wht executescaler method is used?
In a stored procedure 4 select stmts there.If error comes in one select stmt will remaining normally executes?
Show us in simple steps to create setup & deployment project for windows application?
What is serialization in unity?
What is the difference between Hash Table and Arrays?
How do I get deterministic finalization in c#?
What is using directive in c#?
What is parseexact c#?
What are the 2 broad classifications of data types available in c#?
What is a c# delegate?
What is a factory in c#?
Any exceptions are there which are not caught by any catch blocks? what are they?