Menu
Topics Index
...
`

Operators


If you need explanation Read this topic

If you need Answer Take test on this topic

Operators
What will be the output of the following program?
public class Description {
    public static void main(String[] args) {
        int shift = 5000;
        shift >>>= 2;
        System.out.print(shift + ", ");
        shift <<= 3;
        System.out.print(shift + ", ");
        shift = 4;
        shift ^= 2;
        System.out.print(shift + ", ");
        shift = ++shift;
        System.out.print(shift + ", ");
        --shift;
        shift = +shift;
        System.out.print(shift + ", ");
        shift = ~shift;
        System.out.print(shift);
    }
}

A. 625, 5000, 6, 7, 6, -6
B. 1250, 10000, 6, 7, 6, 6
C. 1250, 10000, 6, 7, 6, -7
D. 625, 5000, 6, 7, 6, -7
E. Some other output
F. Compilation Error or Runtime Error
Topic: Java Bitwise Operators

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is c...as shift is +ve shift>>>=2 bcums shift>>2...gives 1250...3left shifts give 10000...xor gives 6....incremented to 7 and decremented to 6...negation gives -6

Posted by Santosh Munugota    2014-03-07 10:30:46


Ans is C.. 5000>>>2 means right shift two times gives 1250 and left shift 3 times gives 10000 and assigning shift to 4 and doing AND operation to it with 2 gives 6. and incremnt gives 7 and then decremnt and making positive..

Posted by Om Prakash Om    2014-03-07 10:36:47


Ans b because first will be execute 5000 shift and next ececute another one

Posted by Prudviraj Regumani    2014-03-07 16:19:42


Congratulations Santosh Munugota. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-10 05:28:31


© meritcampus 2019

All Rights Reserved.

Open In App