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

Việt Quân

New member
What will be the output of the following Java code?
Code:
    class operators 
    {
        public static void main(String args[]) 
        {    
             int x = 8;
             System.out.println(++x * 3 + " " + x);
        } 
    }
A. 24 8
B. 24 9
C. 27 8
D. 27 9
 
Answer: d
Explanation: Operator ++ has higher precedence than multiplication operator, *, x is incremented to 9 than multiplied with 3 giving 27.
output:
Code:
$ javac operators.java
$ java operators
27 9
 

Tìm kiếm

Back
Top