Advertisement
Guest User

Greater_of_Two_Values

a guest
Oct 2nd, 2016
1,326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Greater_of_Two_Values
  8. {
  9.     class Greater_of_Two_Values
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine().ToLower();
  14.             if (input == "int")
  15.             {
  16.                 int first = int.Parse(Console.ReadLine());
  17.                 int second = int.Parse(Console.ReadLine());
  18.                 int outputLarger = GetIntMax(first, second);
  19.                 Console.WriteLine(outputLarger);
  20.             }
  21.             else if (input == "char")
  22.             {
  23.                 char first = char.Parse(Console.ReadLine());
  24.                 char second = char.Parse(Console.ReadLine());
  25.                 char outputLarger = GetCharMax(first, second);
  26.                 Console.WriteLine(outputLarger);
  27.             }
  28.             else
  29.             {
  30.                 string first = Console.ReadLine();
  31.                 string second = Console.ReadLine();
  32.                 string outputLarger = GetStringMax(first, second);
  33.                 Console.WriteLine(outputLarger);
  34.             }
  35.         }
  36.  
  37.         static int GetIntMax(int first, int second)
  38.         {
  39.             int larger = 0;
  40.             if (first >= second) larger = first;
  41.             else larger = second;
  42.             return larger;
  43.         }
  44.  
  45.         static char GetCharMax(char first, char second)
  46.         {
  47.             char larger = (char)0x00;
  48.             if (first >= second) larger = first;
  49.             else larger = second;
  50.             return larger;
  51.         }
  52.  
  53.         static string GetStringMax(string first, string second)
  54.         {
  55.             string larger = string.Empty;
  56.             if (first.CompareTo(second) >= 0) larger = first;
  57.             else larger = second;
  58.             return larger;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement