int i=0;i=i++

package algorithms.com.guan.javajicu; 
public class Inc { 
    public static void main(String[] args) { 
       Inc inc = new Inc(); 
       int i = 234; 
       inc.fermin(i); 
       i= i ++; 
       System.out.println(i);
    
    } 
    void fermin(int i){ 
       i++;
    } 
}

运行结果是234

分析如下

看看字节码就明白了
源代码:

1 public class test{
2 public static void main(String[] args){
3 int i = 234;
4 i = i++;
5 System.out.println(i);
6 }
7 }

 

编译之后的字节码:
public static void main(java.lang.String[]);
0: sipush 234
3: istore_1
4: iload_1
5: iinc 1, 1
8: istore_1
9: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
12: iload_1
13: invokevirtual #3; //Method java/io/PrintStream.println:(I)V
16: return 

 

我们分析一下字节码
0: sipush 234 //将常量234压入操作数栈
3: istore_1 //将操作数栈中的数值存到局部变量区1号位置上
4: iload_1 //将局部变量区1号位置上的值压入操作数栈
5: iinc 1, 1 //将局部变量区1号位置上的数值增1
8: istore_1 //将操作数栈中的数值存到局部变量区1号位置上

 

现在很明显了:它先把i压入栈,然后把i(在原来的位置上)加1,然后又把栈上的旧值写回i。这就导致了i被原来的旧值给覆盖了,所以值没有变化。

转载于:https://www.cnblogs.com/lijingran/p/8823052.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
封装成函数: for(int i = 8; i <= 15; i++){ num[index++] = a4[i]; } for(int i = 8; i <= 15; i++){ num[index++] = a3[i]; } for(int i = 8; i <= 15; i++){ num[index++] = a2[i]; } for(int i = 8; i <= 15; i++){ num[index++] = a1[i]; } for(int i = 0; i <= 7; i++){ num[index++] = a1[i]; } for(int i = 0; i <= 7; i++){ num[index++] = a2[i]; } for(int i = 0; i <= 7; i++){ num[index++] = a3[i]; } for(int i = 0; i <= 7; i++){ num[index++] = a4[i]; } for(int i = 23; i >= 16; i--){ num[index++] = a1[i]; } for(int i = 23; i >= 16; i--){ num[index++] = a2[i]; } for(int i = 23; i >= 16; i--){ num[index++] = a3[i]; } for(int i = 23; i >= 16; i--){ num[index++] = a4[i]; } for(int i = 24; i <= 31; i++){ num[index++] = a4[i]; } for(int i = 24; i <= 31; i++){ num[index++] = a3[i]; } for(int i = 24; i <= 31; i++){ num[index++] = a2[i]; } for(int i = 24; i <= 31; i++){ num[index++] = a1[i]; } for(int i = 40; i <= 47; i++){ num[index++] = a4[i]; } for(int i = 40; i <= 47; i++){ num[index++] = a3[i]; } for(int i = 40; i <= 47; i++){ num[index++] = a2[i]; } for(int i = 40; i <= 47; i++){ num[index++] = a1[i]; } for(int i = 39; i >= 32; i--){ num[index++] = a1[i]; } for(int i = 39; i >= 32; i--){ num[index++] = a2[i]; } for(int i = 39; i >= 32; i--){ num[index++] = a3[i]; } for(int i = 39; i >= 32; i--){ num[index++] = a4[i]; } for(int i = 55; i >= 48; i--){ num[index++] = a1[i]; } for(int i = 55; i >= 48; i--){ num[index++] = a2[i]; } for(int i = 55; i >= 48; i--){ num[index++] = a3[i]; } for(int i = 55; i >= 48; i--){ num[index++] = a4[i]; } for(int i = 56; i <= 63; i++){ num[index++] = a4[i]; } for(int i = 56; i <= 63; i++){ num[index++] = a3[i]; } for(int i = 56; i <= 63; i++){ num[index++] = a2[i]; } for(int i = 56; i <= 63; i++){ num[index++] = a1[i]; }
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值