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 |
Can we have the method in drived class with the same name which is there in base class?
What are the two kinds of properties?
What is the difference between array.find method and arraylist.find method?
Assembly Code. in Rejester AL. How do Contast Replece( or Change): Bit D3 With Bit D4 and Bit D2 With Bit D5 and Bit D1 With Bit D6 and Bit D0 With Bit D7 I am Not Know Very Well Write English.
What is pure abstract class in c#?
How do you sort a list in c#?
What is primitive types in c#?
What is wpf c#?
Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why ?
Can we have only “try” block without “catch” block in c#?
Why multiple inheritance is not possible in c#
Are arraylist faster or arrays?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)