Java学习----运算符与表达式

一.运算符

1.算术运算符

+   -   *   /  %  ++  --

public class Test7 {
    public static void main(String[] args) {
        int x = 10;
        int y = 3;
        float f = 3.5f;
        System.out.println(x/y); // 3
        System.out.println(x%y); // 1
        System.out.println(x/f); // 2.857143  x隐式转换成float
        System.out.println(x%f); // 3.0
        
        y++;
        System.out.println(y); // 4
        y--;
        System.out.println(y); // 3
    }
}

2.赋值运算符
=  +=  -=  *=   /=

3.关系运算符

>   <   >=   <=   ==

4.逻辑运算符

&   |   !  ^   &&  ||

&&左边为假,不再计算右边

||左边为真,不再计算右边

5.位运算符

<<    >>

6.三目运算符

?:

int y = 3

boolean b = y>3?true:false

二.运算符的优先级

 

三.表达式

运算符与操作数的结合

原文地址:https://www.cnblogs.com/dragon1013/p/5032853.html