Create a program named ConsoleAppException that divide 2 numbers and display the result. Ensure that your program implements the exception handling. Again, the program should have a constructor that initialize the result to zero. The calculation should happen in a method named Division() that takes two parameters (num1 and num2). The main method is only used to call the division() method . Use 25 for num1 and 0 for num2
internal class Program
{
static void Main(string[] args)
{
int num1 = 25,
num2 = 0;
Division(num1,num2);
Console.ReadKey();
}
public static void Division(int num1, int num2)
{
int result = 0;
try
{
result = num1 / num2;
Console.WriteLine($"{num1}/{num2} = {result}");
}
catch (Exception)
{
Console.WriteLine("The divisor is zero");
}
}
}
Comments
Leave a comment