English

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

Question

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);
}
}
Short Answer
Advertisements

Solution

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
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 134]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 57. | Page 134
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×