-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole_PalindromeTest.cs
More file actions
36 lines (31 loc) · 955 Bytes
/
Copy pathConsole_PalindromeTest.cs
File metadata and controls
36 lines (31 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
namespace Palindrome
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please write a word, and I will tell you if it is a Palindrome.");
string str = Console.Readline();
int strLen = str.Length;
int strHalfLen;
bool isPal = true;
if (strLen % 2 == 0){
strHalfLen = strLen/2;
}
else
{
strHalfLen = (strLen/2) + 1;
}
for (int i = 0; i < strHalfLen; i++)
{
if (str[i] != str[strLen-i])
{
Console.WireLine($"Sorry, {str} is not a Palindrome.");
break;
}
}
Console.WriteLine($"Wohoo! {str} is indeed a Palindrome");
}
}
}