correct answer is C.
public static void main(String[] args) {
try {
int num = 10;
int div = 0;
int ans = num/div;
}catch(ArithmeticException ae) {
ans = 0 // Pay attention! No semicolon after zero !!
}catch(Exception e) {
System.out.println("Invalid calculation");
}
System.out.println("Answer = " + ans);
}
public static void main(String[] args) {
try {
int num = 10;
int div = 0;
int ans = num/div;
}catch(ArithmeticException ae) {
ans = 0;
}catch(Exception e) {
System.out.println("Invalid calculation");
}
System.out.println("Answer = " + ans);
}
"ans" can't be resolve because is out of the block where was declared.
upvoted 12 times
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
SamAru
Highly Voted 4 years, 6 months agoMPignaProTech
Most Recent 2 months, 2 weeks agoMPignaProTech
3 months agoOmar_Deeb
1 year, 4 months agodsms
1 year, 5 months agodsms
1 year, 5 months agoVicky_65
1 year, 9 months agocarloswork
2 years, 2 months agojuipeng
2 years, 7 months agoWinston123
2 years, 7 months agoEmilioDeBaku
3 years, 6 months agomachineallen
3 years, 8 months agoJimmyson
3 years, 1 month agoKittyyyy
3 years, 1 month agonotkniram
4 years, 1 month agonotkniram
4 years, 1 month agov323rs
4 years, 12 months agobrianhuang881215
3 years, 4 months agoJoseCG
5 years, 2 months agoJoseCG
4 years, 11 months ago