What is the output if 1. The value of lowerLimit is 50 and the value of divisor
ID: 3737168 • Letter: W
Question
What is the output if
1. The value of lowerLimit is 50 and the value of divisor is 10?
2. The value of lowerLimit is 50 and the value of divisor is 0?
3. The value of the lowerLimit is 150 and the value of divisor is 10?
4. The value of lowerLimit is 150 and the value of divisor is 0?
***
Public static void main(String[] args){
scanner console = new scanner(System.in);
int lowerLimit, divisor, result;
try{
lowerLimit = console.nextInt();
divisor = console.nextInt();
result = lowerLimit/divisor;
if (lowerLimit < 100)
throw new Exception(“Lower limit violation.”);
System.out.println(“result = “ + result);
}
catch (Exception e) {
System.out.println(“Exception: “ + e.toString());
}
}
Explanation / Answer
1)Exception: java.lang.Exception: Lower limit violation.
Explanation : Because lowerLimit is 50 which is < 100, hence violation
2)Exception: java.lang.ArithmeticException: / by zero
Explanation : Because divisor is 0, hence exception
3)result = 15
4)Exception: java.lang.ArithmeticException: / by zero
Explanation : Because divisor is 0, hence exception
Thanks, PLEASE RATE.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.