Advertisement
Guest User

Untitled

a guest
Jun 16th, 2020
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. namespace _09._Greater_of_Two_Values
  2. {
  3. using System;
  4.  
  5. public class GreaterOfTwoValues
  6. {
  7. public static void Main()
  8. {
  9. string dataType = Console.ReadLine();
  10. string firstInput = Console.ReadLine();
  11. string secondInput = Console.ReadLine();
  12.  
  13. switch (dataType)
  14. {
  15. case "int":
  16. int firstInt = int.Parse(firstInput);
  17. int secondInt = int.Parse(secondInput);
  18. int resultInt = GetMax(firstInt, secondInt);
  19. Console.WriteLine(resultInt);
  20. break;
  21. case "char":
  22. char firstChar = char.Parse(firstInput);
  23. char secondChar = char.Parse(secondInput);
  24. char resultChar = GetMax(firstChar, secondChar);
  25. Console.WriteLine(resultChar);
  26. break;
  27. case "string":
  28. string firstString = firstInput;
  29. string secondString = secondInput;
  30. string resultString = GetMax(firstString, secondString);
  31. Console.WriteLine(resultString);
  32. break;
  33. }
  34. }
  35.  
  36. public static int GetMax(int first, int second)
  37. {
  38. return Math.Max(first, second);
  39. }
  40.  
  41. public static char GetMax(char first, char second)
  42. {
  43. return (char)Math.Max(first, second);
  44. }
  45.  
  46. public static string GetMax(string first, string second)
  47. {
  48. int comparison = first.CompareTo(second);
  49.  
  50. if (comparison > 0)
  51. {
  52. return first;
  53. }
  54. else
  55. {
  56. return second;
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement