赋值运算符

赋值运算符 :=

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

/*

    赋值运算符 :=

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

*/
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

    }
}

 

posted @ 2019-06-18 20:26  国民老公骚颖  阅读(203)  评论(0编辑  收藏  举报