+ 7
For loop & Catch handling
int n=6; for (int i=0;i <3;++i){ try n/=i; } catch(Exception e){ n+=2; } } //Output:4 tried to solve and i know just a little bit how but i need more explanation why from someone who knows it thank-you😊
2 ответов
+ 7
n=6
loop 1:
n = 6/0 = ~
call cactch block:
n = 6+2= 8
loop 2: n = 8/1 = 8
loop 3: n = 8/2 = 4
end loop
that's why the out put is 4;
+ 3
in the first loop the try block throws an exception (divide by 0 ) so the catch block gets executed (n becomes 8). and the rest is explained very well by @th3_c0d3r