Advertisement
YavorGrancharov

Greater_Of_Two_Values_(Methods)

Jun 12th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.         var type = Console.ReadLine().ToLower();
  8.        
  9.         if (type == "int") {
  10.             int first = int.Parse(Console.ReadLine());
  11.             int second = int.Parse(Console.ReadLine());
  12.             int max = GetMax(first, second);
  13.             Console.WriteLine(max);
  14.         }
  15.        
  16.         if (type == "char") {
  17.             char first = char.Parse(Console.ReadLine());
  18.             char second = char.Parse(Console.ReadLine());
  19.             char max = GetMax((char)first, (char)second);
  20.             Console.WriteLine(max);
  21.         }
  22.        
  23.         if (type == "string") {
  24.             string first = Console.ReadLine();
  25.             string second = Console.ReadLine();
  26.             string max = GetMax(first, second);
  27.             Console.WriteLine(max);
  28.         }
  29.     }
  30.    
  31.     static int GetMax(int first, int second) {
  32.         if (first > second) {
  33.             return first;
  34.         }
  35.         else {
  36.             return second;
  37.         }
  38.     }
  39.    
  40.     static char GetMax(char first, char second) {
  41.         if (first > second) {
  42.             return first;
  43.         }
  44.         else {
  45.             return second;
  46.         }
  47.     }
  48.    
  49.     static string GetMax(string first, string second) {
  50.         if (first.CompareTo(second) > 0) {
  51.             return first;
  52.         }
  53.         else {
  54.             return second;
  55.     }
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement