Java | Operators | Question 2

Predict the output of following Java program. Assume that int is stored using 32 bits.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(A)

7
3
1

(B)



15
7
3

(C)

0
0
0

(D)

1
1
1


Answer: (A)

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

Quiz of this Question



My Personal Notes arrow_drop_up