Advertisement
nsavov

Untitled

Jun 11th, 2019
1,883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06_Middle_Characters
  4. {
  5.     class Program
  6.     {
  7.         static string GetMiddleCharacter(string input)
  8.         {
  9.             int len = input.Length;
  10.             string result = "";
  11.  
  12.             if(len % 2 == 1)
  13.             {
  14.                 result = input[input.Length / 2].ToString();
  15.             }
  16.             else
  17.             {
  18.                 result = input[input.Length / 2 - 1].ToString() + input[input.Length / 2].ToString();
  19.             }
  20.  
  21.             return result;
  22.         }
  23.  
  24.         static void Main(string[] args)
  25.         {
  26.             string input = Console.ReadLine();
  27.  
  28.             Console.WriteLine(GetMiddleCharacter(input));
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement