+ 1
Try/catch body
Can someone please go through the iteration so as to output n as 4 public class Program { public static void main(String[] args) { int n = 6; try { for(int i = 0; i < 3; i++) { n /= i; } } catch (Exception e) { n += 2; } System.out.print(n); } }
1 Antwort
+ 8
n = 6;
i = 0 --> n = 6/0 --> division by zero not allowed --> catch: n = 6+2 = 8
i = 1 --> n = 8/1 = 8
i = 2 --> n = 8/2 = 4
System.out.println(n)
//output 4