Advertisement
VelizarAvramov

08. Greater of Two Values

Nov 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _08._Greater_of_Two_Values
  4. {
  5.     class GreaterOfTwoValues
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.  
  11.             if (input == "int")
  12.             {
  13.                 int first = int.Parse(Console.ReadLine());
  14.                 int second = int.Parse(Console.ReadLine());
  15.                 int result = GetMaxInt(first, second);
  16.                 Console.WriteLine(result);
  17.             }
  18.             else if (input == "char")
  19.             {
  20.                 char first = char.Parse(Console.ReadLine());
  21.                 char second = char.Parse(Console.ReadLine());
  22.                 char result = GetMaxChar(first, second);
  23.                 Console.WriteLine(result);
  24.             }
  25.             else if (input == "string")
  26.             {
  27.                 string first = Console.ReadLine();
  28.                 string second = Console.ReadLine();
  29.                 string result = GetMaxString(first, second);
  30.                 Console.WriteLine(result);
  31.             }
  32.         }
  33.  
  34.         private static string GetMaxString(string first, string second)
  35.         {
  36.             if (first.CompareTo(second) >= 0)
  37.             {
  38.                 return first;
  39.             }
  40.             else
  41.             {
  42.                 return second;
  43.             }
  44.         }
  45.  
  46.         private static char GetMaxChar(char first, char second)
  47.         {
  48.             if (first >= second)
  49.             {
  50.                 return first;
  51.             }
  52.             else
  53.             {
  54.                 return second;
  55.             }
  56.         }
  57.  
  58.         private static int GetMaxInt(int first, int second)
  59.         {
  60.             if (first >= second)
  61.             {
  62.                 return first;
  63.             }
  64.             else
  65.             {
  66.                 return second;
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement