首页 > 编程语言 > 详细

java笔记4之比较运算符

时间:2017-01-09 23:03:06      阅读:186      评论:0      收藏:0      [点我收藏+]

/*
    比较运算符:
        ==,!=,>,>=,<,<=
        
    特点:
        无论你的操作是简单还是复杂,结果是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 }

 

java笔记4之比较运算符

原文:http://www.cnblogs.com/lanjianhappy/p/6266648.html

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