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, y; x = 5 >> 2; y
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, y;
x = 5 >> 2;
y = x>>> 2;
System.out.println(y);
}
}लघु उत्तरीय
Advertisements
उत्तर
Initially, x = 5
1. x = 5 >> 2;
The signed right shift operator (>>) shifts the bits two positions to the right.
x = 5 >> 2 = 1
2. y = x >>> 2;
The unsigned right shift operator (>>>) shifts the bits two positions to the right and fills the leftmost bits with zeros.
y = 1 >>> 2 = 0
Output:
0
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
