Use the Shift operators and display the result.



    1. 20 << 2
    2. 20 >> 2
    3. 20 >>> 2

public class Shift {
public static void main(String[] args) {
int n;
n = 20;
System.out.println("Value of n: " + n);

n = 20 << 2;
System.out.println("Value of n after 20 << 2: " + n);

n = 20 >> 2;
System.out.println("Value of n after 20 >> 2: " + n);
n = 20 >>> 2;
System.out.println("Value of n after 20 >>> 2: " + n);
}
}
/*
Value of n: 20
Value of n after 20 << 2: 80
Value of n after 20 >> 2: 5
Value of n after 20 >>> 2: 5
*/

Post a Comment

Copyright © Rough Record. Designed by OddThemes