import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        // shift right (<<) preserves the sign
        int a = 10;
        int a1 = a >> 2;
        System.out.printf("%d >> 2 = %d\n", a, a1);
        
        int b = -10;
        int b1 = b >> 2;
        System.out.printf("%d >> 2 = %d\n", b, b1);
        
        // shift right zero fill (>>>) does not preserve the sign
        // for negative numbers, since it shifts the MSB,
        // it generates a large positive value.
        int c = -10;
        int c1 = c >>> 2;
        System.out.printf("%d >> 2 = %d\n", c, c1);
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: