Advertisement
gospod1978

Methods-Ex\Middle Characters

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