- Course
- Data types B
- Check numbers with exceptions
Check numbers with exceptions
Last updated:
8/23/2020
⁃
Difficulty:
Easy
Create a C# program that asks the user for a text (x) and converts to check if the text is a number or not.
Input
Jonny
Output
It is not a number
Solution
using System;
public class CheckNumberWithExceptions
{
public static void Main(string[] args)
{
string x = Console.ReadLine();
try
{
Convert.ToInt32(x);
Console.WriteLine("It's a number");
}
catch
{
Console.WriteLine("It is not a number");
}
}
}