What will be the output of the following Java code? [code] class operators { public static void main(String args[])

What will be the output of the following Java code?
Code:
    class operators 
    {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            int var3;
            var3 = ++ var2 * var1 / var2 + var2;
            System.out.print(var3);
        } 
    }
A. 10
B. 11
C. 12
D. 56
 
Answer: c
Explanation: Operator ++ has the highest precedence than / , * and +. var2 is incremented to 7 and then used in expression, var3 = 7 * 5 / 7 + 7, gives 12.
output:
Code:
$ javac operators.java
$ java operators
12
 

Tìm kiếm

Back
Top