Brief description of JAVA operators

 计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量。

Types of operators

Including: arithmetic operators, relational operators, logical operators, etc.

One, arithmetic operators.
One of the most basic uses of computers is to perform mathematical operations. As a computer language, Java also provides a rich set of operators to manipulate variables.
Assuming a=10, b=5.
Insert picture description here
Example display

package test01;

public class test11 {
    
    
    public static void main(String[] args) {
    
    
        int a=10;
        int b=5;
        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("a%b="+(a%b));
        System.out.println("a++ ="+(a++));
        System.out.println("a-- ="+(a--));
        System.out.println("--a ="+(--a));
        System.out.println("++a ="+(++a));
    }
}

The results of the code operation are as follows:
Insert picture description here
Note: The increment and decrement operator
++ is calculated first and then assigned
++ is assigned first and then calculated
(similarly, the operation steps are the same as ++)

Second, the relational operators The
relational operators are as follows:
Insert picture description here
Example display:

package test01;

public class test12 {
    
    

    public static void main(String[] args) {
    
    
        int a = 10;
        int b = 5;
        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) );
    }
}

The code results are as follows:
Insert picture description here
Third, logical operators The
logical operators are as follows:
Insert picture description here
Example display:

package test01;

public class test06 {
    
    
    public static void main(String[] args) {
    
    
        int a = 8;
        int b = 10;
        boolean bool = a<10 && b<9;
        boolean boole = a<10 || b<9;
        System.out.println(bool);
        System.out.println(boole);
    }
}

The results are as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/tan1024/article/details/109751774