What is the output of the following code?
1: public class Main { 2: public static void main(String[] args) { 3: int x = 5 * 4 % 3; 4: System.out.println(x); 5: } 6:}
A.
The * and % have the same operator precedence, so the expression is evaluated from left-to-right.
The result of 5 * 4 is 20, and 20 % 3 is 2 (20 divided by 3 is 18, the remainder is 2).
The output is 2 and option A is the correct answer.