Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Java | Operators | Question 1

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Predict the output of following Java Program




class Test {
    public static void main(String args[])  {
       int x = -4;
       System.out.println(x>>1);  
       int y = 4;
       System.out.println(y>>1);  
    }   
}

(A) Compiler Error: Operator >> cannot be applied to negative numbers
(B)

-2
2

(C)

2
2

(D)

0
2


Answer: (B)

Explanation: See https://www.geeksforgeeks.org/bitwise-shift-operators-in-java/

Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads