zoukankan      html  css  js  c++  java
  • 慕课网-安卓工程师初养成-3-4 Java中的比较运算符

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

     

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

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

    注意哦:

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

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

    任务

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

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

     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 }
  • 相关阅读:
    MySQL 练习题
    MySQL 增删查改
    HTML显示与隐藏
    360布局
    div布局
    HTML练习2
    HTML练习

    if语句的用法及其案例
    输入输出,数据类型与运算符
  • 原文地址:https://www.cnblogs.com/chenliting/p/3960606.html
Copyright © 2011-2022 走看看