Java笔记10——关系运算符

前言

Java的关系运算符在条件判断的时候经常用到,那么关系运算符有哪些呢?下面为大家介绍Java的关系运算符。

关系运算符

下面表格中的实例整数变量A的值为1,变量B的值为2:
Java笔记10——关系运算符_第1张图片

代码实例

public class Test {
 
  public static void main(String[] args) {
     int a = 10;
     int b = 20;
     System.out.println("a == b = " + (a == b) );
     System.out.println("a != b = " + (a != b) );
     System.out.println("a > b = " + (a > b) );
     System.out.println("a < b = " + (a < b) );
     System.out.println("b >= a = " + (b >= a) );
     System.out.println("b <= a = " + (b <= a) );
  }
}

运行结果为

a == b = false
a != b = true
a > b = false
a < b = true
b >= a = true
b <= a = false

你可能感兴趣的:(Java)