java20

42 阅读1分钟

Java 运算符(关系运算符)

一、关系运算的逻辑操作

关系运算的逻辑操作可以使用:>、<、>=、<=、!=、==。

所有的关系运算符判断完成的数据返回结果都是布尔类型(boolean)。


public class TestDemo  {
public static void main (String args [ ]) {

int x = 10  ;

int y = 20  ;

System.out.println (x > y) ;    False 

System.out.println (x < y) ;    True 

System.out.println (x == y) ;    

System.out.println (x = y ? x * 2 : y - 3) ;    17

}
}

 

二、可以直接进行字符与数字的判断

public class TestDemo  {

public static void main (String args [ ]) {

System.out.ptintln( ‘a’ == 97) ;    True 

}

}

这类代码虽然出现较少,但依然会在讲课中作为操作原理进行分析。