Created
December 12, 2025 10:04
-
-
Save zuriby/602b4e7159e8cb4eda3aa5e06412cb14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Console.WriteLine("Enter two integers (separated by comma or space):"); | |
| string[] parts = Console.ReadLine().Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries); | |
| if (parts.Length == 2 && int.TryParse(parts[0], out int a) && int.TryParse(parts[1], out int b)) | |
| { | |
| Console.WriteLine(Math.Max(a, b)); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Invalid input. Please enter exactly two integers separated by comma or space."); | |
| } | |
| ``` | |
| **What's happening:** | |
| - `Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries)` — handles both delimiters and ignores extra spaces | |
| - `int.TryParse(..., out int a)` — attempts to parse; returns `false` if it fails (no exceptions) | |
| - `Math.Max(a, b)` — returns the larger of the two | |
| **Sample runs:** | |
| ``` | |
| Enter two integers (separated by comma or space): | |
| 37, 73 | |
| 73 | |
| Enter two integers (separated by comma or space): | |
| 5 3 | |
| 5 | |
| Enter two integers (separated by comma or space): | |
| hello world | |
| Invalid input. Please enter exactly two integers separated by comma or space. |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Console.WriteLine("Enter two integers (separated by comma or space):");
string[] parts = Console.ReadLine().Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 2 && int.TryParse(parts[0], out int a) && int.TryParse(parts[1], out int b))
{
Console.WriteLine(Math.Max(a, b));
}
else
{
Console.WriteLine("Invalid input. Please enter exactly two integers separated by comma or space.");
}