zoukankan      html  css  js  c++  java
  • Java学习——Java运算符

    位运算符

    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
  • 相关阅读:
    2017寒假练习赛总结(实时更新)
    NOIP
    挖坑--总结
    BZOJ3709: [PA2014]Bohater
    BZOJ3714: [PA2014]Kuglarz
    BZOJ2276: [Poi2011]Temperature
    VIJOS P1543极值问题
    BZOJ2749: [HAOI2012]外星人
    BZOJ2173: 整数的lqp拆分
    BZOJ1100: [POI2007]对称轴osi
  • 原文地址:https://www.cnblogs.com/kaituorensheng/p/5750817.html
Copyright © 2011-2022 走看看