1. Assume you are reading students grades from user for final exam, grades are s
ID: 3719215 • Letter: 1
Question
1. Assume you are reading students grades from user for final exam, grades are supposed to
be between 0 and 100 inclusively. Write a program that can handle any type of number that
is typed by the user, where you distinguish between negative grades, grades above 100, and
non-integer inputs.
2. Given the code below, when m1(2) is invoked, m2() throws an ArithmeticException and
what will m1() return?
public int m1(int x) {
int count=1;
try {
count += x;
count += m2(count);
count++;
}
catch(Exception e) { count -= x; }
return count;
}
Explanation / Answer
m1(2)
=> count = 1 , then count = 1 + 2 = 3
Then ArithmeticException is thrown and it is being caught and value is decemented by 2
count = 3 - 2 = 1
hence 1 is returned by m1
Thanks, let me know if there is any concenr.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.