java笔记4之比较运算符
/*
比较运算符:
==,!=,>,>=,<,<=
特点:
无论你的操作是简单还是复杂,结果是boolean类型。
注意事项:
"=="不能写成"="。
*/
1 class OperatorDemo { 2 public static void main(String[] args) { 3 int x = 3; 4 int y = 4; 5 int z = 3; 6 7 System.out.println(x == y); 8 System.out.println(x == z); 9 System.out.println((x+y) == (x+z)); 10 System.out.println("------------"); 11 12 System.out.println(x != y); 13 System.out.println(x > y); 14 System.out.println(x >= y); 15 System.out.println(x < y); 16 System.out.println(x <= y); 17 System.out.println("------------"); 18 19 int a = 10; 20 int b = 20; 21 22 //boolean flag = (a == b); 23 //boolean flag = (a = b); //这个是有问题的,不兼容的类型 24 //System.out.println(flag); 25 26 int c = (a = b); //把b赋值给a,然后把a留下来 27 System.out.println(c); 28 } 29 }