ExceptionS Consider the following Java code: int lowerLimit, result, divisor; ..
ID: 3650980 • Letter: E
Question
ExceptionSConsider the following Java code:
int lowerLimit, result, divisor;
...
try
{
result = lowerLimit / divisor;
if (lowerLimit < 100)
throw new Exception("Lower limit violation.");
}
catch (ArithmeticException e)
{
result = 110;
}
catch (Exception e)
{
result = 100;
}
What is the value of result if the value of lowerLimit is 50 and the value of divisor is 10?
What is the value of result if the value of lowerLimit is 50 and the value of divisor is 0?
What is the value of result if the value of lowerLimit is 150 and the value of divisor is 10?
What is the value of result if the value of lowerLimit is 150 and the value of divisior is 0?
Explanation / Answer
100 110 15 110 If everything goes well, no exception code will execute, that's why answer #3 is 150/10 if divisor is 0, an AirthmeticException exception will be throwed line 1 : result = lowerLimit / divisor; line 2 : if (lowerLimit < 100) line 3 : throw new Exception("Lower limit violation."); line4 : } if divisor is 0, line 1 throw AirthmeticException even though lowerLimit < 100. After line1 throw AirthmeticException, line2 will never execute. THe program will go directly to AirthmeticException catch blockRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.