开发者社区> 问答> 正文

Java中 System.out.println(count++)输出结果没有自增

public class CountTest{
public static void main(String[] args){
int count = 20 ;
        System.out.println(count++);

}
}

//输出的结果为20,不是21,求解

展开
收起
蛮大人123 2016-03-24 14:41:59 3130 0
3 条回答
写回答
取消 提交回答
  • count++ 是先返回count后执行自增操作,++count 才是自增后再返回结果。
    2019-07-17 19:12:45
    赞同 展开评论 打赏
  • 这样写:System.out.println(++count),++写在后面表示先print,再++;++写在前面表示先++,再print
    2019-07-17 19:12:45
    赞同 展开评论 打赏
  • 我说我不帅他们就打我,还说我虚伪

    System.out.println(++count);//这个是21 先运行++count,后输出
    System.out.println(count++); //这个是20 先输出 ,后运行count++如果你再输出一行就看到效果了.

    2019-07-17 19:12:45
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载