Activity 1.5.1.
- The code first prints "Condition met" and then prints "End of program"
- Since the first condition is false, the if condition is false and the program skips its body.
- The code only prints "End of program"
- The first condition x > 10 is false, so the short-circuit evaluation prevents the execution of x / y > 10. This avoids a division by zero error. Therefore, only "End of program" is printed.
- The code throws an error for division by zero
- Since the first condition is false, the program does’t bother checking the rest of conjoined conditions and it evaluates the if condition as false.
- Nothing will be printed
Consider the following Java function. What happens when the function is called with the given inputs
print(3, 0, 0);
?public static void print(int x, int y, int z) {
if (x > 10 && x / y > 10 && z > 10) {
System.out.println("Condition met");
}
System.out.println("End of program");
}