首页 > 编程语言 > 详细

Java学习——Java运算符

时间:2016-08-08 20:59:49      阅读:231      评论:0      收藏:0      [点我收藏+]

位运算符

A = 0011 1100
B = 0000 1101
-----------------
A&b = 0000 1100
A | B = 0011 1101
A ^ B = 0011 0001
A << 2 = 1111 0000
A >>> 2 = 0000 1111 ~A= 1100 0011

例子

package import_test;

public class Employee {public static void main(String args[]){int a = 60;
        int b = 13;
        System.out.println(a | b);
        System.out.println(a & b);
        System.out.println(a ^ b);
        System.out.println(~a);
        System.out.println(a << 2);
        System.out.println(a >>> 2);
        
    }
}

 结果

61
12
49
-61
240
15

条件运算符

public class Employee {
    public static void main(String args[]){
        int a = 10;
        int b = 8;
        String rev = a > b ? "a > b" : "a<= b";
        System.out.println(rev);
    }
}

结果

a > b

instanceOf运算符

public class Employee {
    public static void main(String args[]){
        Employee eg = new Employee();
        String s = "String";

        System.out.println(s instanceof String);
        System.out.println(eg instanceof Employee);
        //boolean b = s instanceof Employee);
        //System.out.println(b);
    }
}

结果

true
true

 

Java学习——Java运算符

原文:http://www.cnblogs.com/kaituorensheng/p/5750817.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!