java中>>和>>>符号的区别

一道笔试题

public class Demo01 {
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int x , y ;
        x = 5 >> 2 ;
        y = x >>> 2 ;
        System.out.println(y);
    }

}

输出结果应该为?

0。

>>是左移,>>>是无符号左移

public class Demo01 {
    
    public static void main(String[] args) {
        
        int x = 2,y = -2;
        System.out.println(x>>1);    //1
        System.out.println(y>>1);    //-1
        System.out.println(y>>>1);    //2147483647
        
    }

}
Last modification:November 13th, 2019 at 06:34 pm
如果觉得我的文章对你有用,请随意赞赏