{ ?? public static void main (String[]arge){ ?? ?int o = 10 ; ??? int p = 20 ; ??? int a = (o+p);?????????????????????? //a=30 ??? int b = (a+=o);??????????????????? //a=40 b=40,此時(shí)a的值已改變 ??? int c = (b-=o);???????????????????? //b=30 c=30,此時(shí)b值已改變 ??? long d = (c*=o);???????????????? //c=300 d=300,此時(shí)c值已改變
??? long e = (d/=o);???????????????? //d=30 e=30,此時(shí)d值已改變
??? long f = (e%=o);//e=0 f=0 ??? System.out.println("three = one + two ==>"+a);????????? //輸出值為改變后的值40 ??? System.out.println("three += one ==>"+b); ??? System.out.println("three -= one ==>"+c); ??? System.out.println("three *= one ==>"+d); ??? System.out.println("three /= one ==>"+e); ??? System.out.println("three %= one ==>"+f); ???? ?
int b = (a+=o); 在你這行的代碼中,你的a已經(jīng)等于a+0了,也就是說(shuō)你的a經(jīng)過(guò)運(yùn)算已經(jīng)等于40了。java是逐行運(yùn)算下來(lái)的,你的顯示代碼是放在最后所以顯示的是最后賦值的結(jié)果也就是40而不是第一次運(yùn)算的30.
2017-05-11
{
?? public static void main (String[]arge){
?? ?int o = 10 ;
??? int p = 20 ;
??? int a = (o+p);?????????????????????? //a=30
??? int b = (a+=o);??????????????????? //a=40 b=40,此時(shí)a的值已改變
??? int c = (b-=o);???????????????????? //b=30 c=30,此時(shí)b值已改變
??? long d = (c*=o);???????????????? //c=300 d=300,此時(shí)c值已改變
??? long e = (d/=o);???????????????? //d=30 e=30,此時(shí)d值已改變
??? long f = (e%=o);//e=0 f=0
??? System.out.println("three = one + two ==>"+a);????????? //輸出值為改變后的值40
??? System.out.println("three += one ==>"+b);
??? System.out.println("three -= one ==>"+c);
??? System.out.println("three *= one ==>"+d);
??? System.out.println("three /= one ==>"+e);
??? System.out.println("three %= one ==>"+f);
???? ?
}
}
2017-05-11
最后兩個(gè)}}請(qǐng)無(wú)視,大家試試這段代碼輸出有什么問(wèn)題