public class HelloWorld{ public static void main(String[] args) { int age1=24; int age2=18; int age3=36; int age4=27; int sum=age1+age2+age3+age4; double avg=sum/4; int minus=age1-age2; int newAge=--age1; System.out.println("年齡總和:
為什么自減--在age1后面就錯了呢?
2016-03-13
’=‘表示賦值,先執(zhí)行右邊的表達(dá)式或值,再賦值給左邊,你這個右邊是‘ --age1’先自減1再賦的值
2016-03-13
自減--放在age1后面,就是先把a(bǔ)ge的值賦給newAge,然后age再自減
2016-03-13
int newAge=--age1;
表示先進(jìn)行“--”age1的自減再進(jìn)行"="賦值,此時newAge的值為(age1-1)。
int newAge=age1--;
表示先進(jìn)行“=”賦值,再進(jìn)行"--"age1的自減,此時newAge的值為(age1)。
2016-03-13
int newAge=--age1;
表示先進(jìn)行“--”age1的自減再進(jìn)行"="賦值,此時newAge的值為(age1-1)。
int newAge=age1--;
表示先進(jìn)行“=”賦值,再進(jìn)行"--"age1的自減,此時newAge的值為(age1)。