Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string input = Console.ReadLine();
- if(input == "int")
- {
- int intOne = int.Parse(Console.ReadLine());
- int intTwo = int.Parse(Console.ReadLine());
- int max = ReturnMax(intOne, intTwo);
- }
- else if(input == "char")
- {
- char charOne = char.Parse(Console.ReadLine());
- char charTwo = char.Parse(Console.ReadLine());
- char biggerChar = ReturnMax(charOne, charTwo);
- }
- else if(input == "string")
- {
- string stringOne = Console.ReadLine();
- string stringTwo = Console.ReadLine();
- string max = ReturnMax(stringOne, stringTwo);
- }
- }
- private static int ReturnMax(int intOne, int intTwo)
- {
- int max = 0;
- if(intOne > intTwo)
- {
- max = intOne;
- }
- else if(intOne < intTwo)
- {
- max = intTwo;
- }
- return max;
- }
- private static char ReturnMax(char charOne, char charTwo)
- {
- char max = ' ';
- if(charOne > charTwo)
- {
- max = charOne;
- }
- else if(charOne < charTwo)
- {
- max = charTwo;
- }
- return max;
- }
- private static string ReturnMax(string stringOne, string stringTwo)
- {
- // "Helloz"
- // "Mellow"
- string max = "";
- int shorterStringLength = 0;
- if(stringOne.Length < stringTwo.Length)
- {
- shorterStringLength = stringOne.Length;
- }
- else if (stringTwo.Length < stringOne.Length)
- {
- shorterStringLength = stringTwo.Length;
- }
- bool maxFound = false;
- for (int i = 0; i < shorterStringLength; i++)
- {
- char currentInStringOne = stringOne[i];
- char currentInStringTwo = stringTwo[i];
- if(currentInStringOne > currentInStringTwo)
- {
- max = stringOne;
- maxFound = true;
- break;
- }
- else if(currentInStringTwo > currentInStringOne)
- {
- max = stringTwo;
- maxFound = true;
- break;
- }
- }
- if(maxFound == false)
- {
- max = "empty output";
- }
- return max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement