先++与后++的区别

先++是先+1再参与表达式运算,后++是先参与表达式运算,当前语句代码(分号标识)执行完成后再加1.

源码和输出结果

 

 

源码如下

package top.lishuoboy.study;

public class BBB {

	public static void main(String[] args) {
		int count1 = 0;
		System.out.println(++count1 + 10);

		int count2 = 0;
		System.out.println(count2++ + 10);

		int count3 = 0;
		count3 = count3 + 1; // 相当于 count3++,不信看源码
		count3 = count3 + 2; // 相当于 count3 += 2,不信看源码
		count3 = count3 + 1 + 1; 

	}

}

 

posted on 2019-09-05 22:33  小石头小祖宗  阅读(15)  评论(0)    收藏  举报  来源

导航