Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter the type of the values: ");
- string type = Console.ReadLine();
- switch (type)
- {
- case "int":
- Console.Write("Enter the first value: ");
- int num1 = int.Parse(Console.ReadLine());
- Console.Write("Enter the second value: ");
- int num2 = int.Parse(Console.ReadLine());
- GetMax(num1, num2);
- break;
- case "char":
- Console.Write("Enter the first char: ");
- string char1 = Console.ReadLine();
- Console.Write("Enter the second char: ");
- string char2 = Console.ReadLine();
- char charOne = char1[0];
- char charTwo = char2[0];
- GetMax(charOne, charTwo);
- break;
- case "string":
- Console.Write("Enter the first string: ");
- string str1 = Console.ReadLine();
- Console.Write("Enter the second string: ");
- string str2 = Console.ReadLine();
- GetMax(str1, str2);
- break;
- default:
- Console.WriteLine("Invalid input type!");
- break;
- }
- }
- static void GetMax(int num1,int num2)
- {
- if(num1 > num2)
- {
- Console.WriteLine(num1);
- }
- else if(num2 > num1)
- {
- Console.WriteLine(num2);
- }
- else
- {
- Console.WriteLine("The numbers are equal!");
- }
- }
- static void GetMax(char char1,char char2)
- {
- if(char1 > char2)
- {
- Console.WriteLine(char1);
- }
- else if(char2 > char1)
- {
- Console.WriteLine(char2);
- }
- else
- {
- Console.WriteLine("The chars are the same!");
- }
- }
- static void GetMax(string str1,string str2)
- {
- if(str1.Length > str2.Length)
- {
- Console.WriteLine(str1);
- }
- else if(str2.Length > str1.Length)
- {
- Console.WriteLine(str2);
- }
- else
- {
- int count = 0;
- foreach(char i in str1)
- {
- if(i > str2[count])
- {
- Console.WriteLine(str1);
- break;
- }
- else if (i < str2[count])
- {
- Console.WriteLine(str2);
- break;
- }
- else
- {
- count++;
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment