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,右边不会进行判断

}

猜你喜欢

转载自www.cnblogs.com/zhaotao11/p/10205852.html