
Patrick B. answered 10/30/20
Math and computer tutor/teacher
/*******************************************************
//********************* 10/30/2020*****************
Returns true if string is a palindrome
*********************************************************/
using System.IO;
using System;
class Program
{
public bool IsPalindrome(string inbuff)
{
int iLeft=0;
int iRight=inbuff.Length-1;
bool boolReturn = true;
while (iLeft<iRight)
{
String leftChar = inbuff.Substring(iLeft,1);
String rightChar = inbuff.Substring(iRight,1);
//Console.WriteLine(leftChar);
//Console.WriteLine(rightChar);
if (string.Compare(rightChar.ToUpper(), leftChar.ToUpper())==0)
{
}
else
{
boolReturn=false;
break;
}
iLeft++; iRight--;
}
return(boolReturn);
}
void Go()
{
string inputStr = "ABBA";
//string inputStr = "ABACADABRA";
//string inputStr = "ABCDEFGFEDCBA"; //<-- change the chars
// string inputStr = "ABCDEFGGFEDCBA"; //<--- to test
Console.Write(inputStr);
if (IsPalindrome(inputStr))
{
Console.WriteLine(" is a palindrome");
}
else
{
Console.WriteLine(" is not a palindrome");
}
}
static void Main()
{
Console.WriteLine("Hello, World!");
Program x = new Program();
x.Go();
}
}
/******************************************************************************
Capitalizes every other word in the string
*********************************/
using System.IO;
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
string inputStr = "the quick brown fox jumped over the lazy dogs";
string [] tokens = inputStr.Split(' ');
int i=0;
foreach (string token in tokens)
{
if (token.Trim() != "")
{
if ((i%2)==1) //every other token gets capitalized
{
Console.Write(token);
}
else
{
//separates the first character from the rest of the token string
string firstChar = token.Substring(0,1);
int N = token.Length;
string restOfTheToken = token.Substring(1,N-1);
//captialization occurs here
string outBuff =string.Concat(firstChar.ToUpper(),restOfTheToken);
Console.Write(outBuff);
}
Console.Write(" ");
i++;
} //non-empty tokesn
} //foereach
}
}
******************* 10/29/2020
Palindrome
Is not the name of the method...
The method is Check()
palindrome is a local var inside check() which main() cannot see until it gets returned...
But in your code you are not checking the return value
In main either do:
If (Check(input))
Or
bool bReturn = Check(input):
If (bReturn)
...
Lily P.
Oops it got messy, I think i will do a new question for my rewriting10/30/20

Patrick B.
Here ya go.... I rewrote the algorithm, which works like this: points at the first and last characters... while the pointers have not yet crossed { compares the characters at each location.. if they do not match, then it's not a palindrome increments/decrements the pointers } As I am using an online interpreter, it will not let me do Console I/O without throwing all kinds of excpetions and hissy-fits... But it does work! You can change the strings inside the Go() routine to test it. Thanks!10/31/20

Patrick B.
I believe you also ordered code that capitalizes every other word in the string. So there ya go!10/31/20
Lily P.
Wow, so amazing! Thank you so much sir! You are legendary10/31/20
Lily P.
Thank you for your answer: I have rewritten my code: static bool Palindrome (string input) { bool pal; string check = ""; for (int i = input.Length; i >= 0; i--) { check = check + input[i]; } if(check == input) { pal = true; } else { pal = false; } return pal; } static void Main(string[] args) { Console.Write("Write a word: "); bool palindrome = Palindrome(Console.ReadLine()); if (palindrome == true) { Console.WriteLine("Ordet är en palindrom"); } else { Console.WriteLine("Ordet är inte en palindrom"); } Console.ReadKey(); It still does not accept my code :(10/30/20