Advertisement
Spocoman

06. Middle Characters

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