Answer to Question #324803 in C# for GEO

Question #324803

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

1
Expert's answer
2022-04-06T13:55:15-0400
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");
            }
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS