赋值运算符

赋值运算符 :=

扩展赋值运算符 :+=, -=, *=, /=, %=

/*

    赋值运算符 :=

    扩展赋值运算符 :+=, -=, *=, /=, %=

*/
public class SetValueTest{

    public static void main(String[] args){
    
    
        int a = 10;
        a += 5; //可以理解成 a = a + 5
        System.out.println(a);

        System.out.println("-----------面试题-------------------");

        byte b = 10;
        //b = b + 5; 编译不通过,因为byte参与运算会提升为int
        b += 5; //不会改变原来变量的类型。
        System.out.println(b);

        System.out.println("-----------课后题--------------------");

        int i = 1;
        i *= 0.1;
        System.out.println(i);//0
        i++;
        System.out.println(i);//1

    }
}
原文地址:https://www.cnblogs.com/zmy-520131499/p/11047441.html