What gets displayed on the screen when the following program is compiled and run. Select the one correct answer. public class test{ public static void main(String args[]){ int x; x = -3 >> 1;
Advertisements
प्रश्न
What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.
public class test{
public static void main(String args[]){
int x;
x = -3 >> 1;
x = x >>> 2;
x = x<<1;
System.out.println(x);
}
}दीर्घउत्तर
Advertisements
उत्तर
Initially, x = −3
1. x = -3 >> 1;
The signed right shift operator (>>) shifts the bits one position to the right while preserving the sign.
x = −2
2. x = x >>> 2;
The unsigned right shift operator (>>>) shifts the bits two positions to the right and fills the leftmost bits with zeros.
x = 1073741823
3. x = x << 1;
The left shift operator (<<) shifts the bits one position to the left.
x = 2147483646
Output:
2147483646
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
