Advertisement
MZlatev

Untitled

Oct 18th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _6._MiddleCharacters
  4. {
  5. class MiddleCharacters
  6. {
  7. static void Main()
  8. {
  9. string word = Console.ReadLine();
  10.  
  11. Console.WriteLine(GetMiddleCharacter(word));
  12. }
  13.  
  14. static string GetMiddleCharacter(string word)
  15. {
  16. string middleChar = null;
  17.  
  18. if (word.Length % 2 == 1)
  19. {
  20. middleChar = word[word.Length / 2].ToString();
  21. }
  22.  
  23. else
  24. {
  25. middleChar = word[word.Length / 2 - 1].ToString() + word[word.Length / 2].ToString();
  26. }
  27.  
  28.  
  29. return middleChar;
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement