Advertisement
Guest User

Methods - GreaterOfTwoValues1

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