java基础知识——运算符

三元运算符
public static void main(String[] args) 
    {
        System.out.println(3>2?"正确":"错误");
        String str="中国"
    }
逻辑运算符
public static void main(String[] args) 
    {
        //&:当两边有一个false,结果为false
        System.out.println(true&true);
        System.out.println(true&false);
        System.out.println(false&false);
        //|:当两边有一个值是true,结果为true
        System.out.println(true|true);
        System.out.println(true|false);
        System.out.println(false|false);
        //^:当两边值相同时为false,不同为true
        System.out.println(true^true);
        System.out.println(true^false);
        System.out.println(false^false);
        //!:取反
        System.out.println(!true);
        System.out.println(!false);
        //&&:和一个&输出结果上没有区别
        System.out.println(true&&true);
        System.out.println(true&&false);
        System.out.println(false&&false);
        //&与两个&&(短路与)的区别
        //&:不管左边值是true还是false,右边都会进行判断
        //&&:如果左边的值为false,右边不会进行判断
        //||:和一个|输出结果上没有区别
        System.out.println(true||true);
        System.out.println(true||false);
        System.out.println(false||false);
        //|与两个||(短路或)的区别
        //|:不管左边值是true还是false,右边都会进行判断
        //&&:如果左边的值为true,右边不会进行判断
    }

 

posted @ 2019-01-01 20:24  帅涛  阅读(145)  评论(0编辑  收藏  举报