Advertisement
Guest User

09. Palindrome Integers

a guest
Oct 10th, 2019
1,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09._Palindrome_Integers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = string.Empty;
  10.             while ((input = Console.ReadLine()) != "END")
  11.             {
  12.                 bool isIntegerPalindrome = ReturnsIsNumberPalindrome(input);
  13.                 if (isIntegerPalindrome)
  14.                 {
  15.                     Console.WriteLine("true");
  16.                 }
  17.                 else
  18.                 {
  19.                     Console.WriteLine("false");
  20.                 }
  21.             }
  22.         }
  23.  
  24.         static bool ReturnsIsNumberPalindrome(string input)
  25.         {
  26.             int number = int.Parse(input);
  27.             bool result = false;
  28.             if (number >= 0 && number <= 9)
  29.             {
  30.                 result = true;
  31.             }
  32.             else
  33.             {
  34.                 for (int i = 0; i < input.Length / 2; i++)
  35.                 {
  36.                     if (input[i] == input[input.Length - 1])
  37.                     {
  38.                         result = true;
  39.                     }
  40.                     else
  41.                     {
  42.                         break;
  43.                     }
  44.                 }
  45.             }
  46.             return result;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement