Introductionto Programming | My Assignment Tutor

T121: ICT102 Introductionto ProgrammingTutorial 11 Topic:Submission:Description:Debugging and Exception HandlingA day after your tutorial Session. This tutorial will introduce you to Exception Handling and Run Time Errors. You should beable to understand difference between Syntax (compiler) and run time (Exceptions) errors.Also, to handle run time errors for graceful exit of programs.Exercise 1: Output of the program and Run Time Errors1. What is printed by the following application?public class Example1{public static void main(String[] args){int denominator, numerator, ratio;numerator = 5;denominator = 2;ratio = numerator / denominator;System.out.println(“The answer is: “+ratio);System.out.println(“Done.”); // Don’t move this line}}2. Change the value of denominator to 0. What runtime error message is now generatedby this application?3. Change the value of denominator to 0. What runtime error message is now generatedby this application?4. Add a try-catch statement to this application. Specifically, put only the statement thatgenerated the exception inside of the try block and put no statements in the catchblock. (Hint: You should be able to determine what exception to catch from the errormessage that you received during the previous step. You should also be able todetermine the line number of the statemen that generated the exception if you didn’tchange the white space.) What statements are now in the body of the main() method?5. Modify the body of the main method as denominator, numerator, ratio;numerator = 5;denominator = 0;try{ratio = numerator / denominator;System.out.println(“The answer is: “+ratio);}catch (ArithmeticException ae){System.out.println(“Divide by 0.”);}System.out.println(“Done.”); // Don’t move this line6. Will this version of the application compile? Why or why not?Exercise 2: ArrayOutofBound// A Common cause index out of boundpublic class NewClass2{public static void main(String[] args){int ar[] = {1, 2, 3, 4, 5};for (int i=0; i


Leave a Reply

Your email address will not be published. Required fields are marked *