码迷,mamicode.com
首页 > 移动开发 > 详细

慕课网-安卓工程师初养成-3-4 Java中的比较运算符

时间:2014-09-07 18:26:25      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   java   ar   strong   数据   div   

来源:http://www.imooc.com/code/1299

 

比较运算符用于判断两个数据的大小,例如:大于、等于、不等于。比较的结果是一个布尔值( true 或 false )。

Java 中常用的比较运算符如下表所示:

bubuko.com,布布扣

注意哦:

1、  > 、 < 、 >= 、 <= 只支持左右两边操作数是数值类型

2、  == 、 != 两边的操作数既可以是数值类型,也可以是引用类型

任务

验证一下你的学习成果吧!

请在编辑器中的第 7 、 8 、 9 、 10 行中添加正确的比较运算符,实现如下运行结果:

bubuko.com,布布扣

 

 1 public class HelloWorld{
 2     public static void main(String[] args) {
 3         int a=16;
 4         double b=9.5;
 5         String str1="hello";
 6         String str2="imooc";
 7         System.out.println("a等于b:" + (a   b));
 8         System.out.println("a大于b:" + (a   b));
 9         System.out.println("a小于等于b:" + (a   b));
10         System.out.println("str1等于str2:" + (str1   str2));
11     }
12 }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 1 public class HelloWorld{
 2     public static void main(String[] args) {
 3         int a=16;
 4         double b=9.5;
 5         String str1="hello";
 6         String str2="imooc";
 7         System.out.println("a等于b:" + (a == b));
 8         System.out.println("a大于b:" + (a   >= b));
 9         System.out.println("a小于等于b:" + (a <= b));
10         System.out.println("str1等于str2:" + (str1 == str2));
11     }
12 }

 

慕课网-安卓工程师初养成-3-4 Java中的比较运算符

标签:style   blog   http   color   java   ar   strong   数据   div   

原文地址:http://www.cnblogs.com/chenliting/p/3960606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!