[Brick Java] Relational Operators

  • relational operator
  • Relational operators, also known as "comparison operators", are used to compare and determine the size of two variables or constants.
  • The results of relational operators are all boolean, that is, either true or false.
  • The precedence of relational operators are: >, <, >=, <= have the same precedence and are higher than !=, == which have the same precedence. The precedence of relational operators is higher than that of assignment operators and lower than that of arithmetic operators, and the association direction is left-to-right.
  • Relational expressions are often used in the condition of an if construct or in the condition of a loop construct.
  • Expressions composed of relational operators are called relational expressions. a > b
  • for example
  • package demo01;
    
    public class demo4 {
        public static void main(String[] args) {
            int a = 6;
            int b = 3;
            System.out.println(a > b);//true
            System.out.println(a >= b);//true
            System.out.println(a <= b);//false
            System.out.println(a < b);//false
            System.out.println(a == b);//false
            System.out.println(a != b);//true
            boolean p1 = a > b;//true
            System.out.println("p1="+p1);//p1=true
        }
    }
    

 

Guess you like

Origin blog.csdn.net/m0_62069409/article/details/124341041