为了账号安全,请及时绑定邮箱和手机立即绑定

关于位运算的判断 求大神看一下代码 遇到个有点奇怪的事

关于位运算的判断 求大神看一下代码 遇到个有点奇怪的事

Smart猫小萌 2019-03-27 13:14:05
String string=Integer.toBinaryString(11);            a=string.toCharArray();            length=a.length;            for (int i = 0; i < a.length; i++) {                System.out.println(a[i]);            }            System.out.println("right to one "+string+" string's length"+string.length());            /*for (int i = 0; i < a.length; i++) {                System.out.println(a[i]);            }*/            if (length==4) {                if (a[1]==1) {                    if (a[2]==1) {                        if (a[3]==1) {                            System.out.println("十字键一定key  LR 一定是key");                        }else {                            System.out.println("十字dpad   LR一定key");                        }                    }else {                        if (a[3]==1) {                            System.out.println("十字--touch  LR一定key");                        }else {                            System.out.println("LR must key");                        }                    }                }else {                                        System.out.println("a[2]"+a[2]);                    if (a[2]==1) {                        if (a[3]==1) {                            System.out.println("十字一定key  LR touch");                        }else {                            System.out.println("十字dpad  LR  touch");                        }                    }else {                        if (a[3]==1) {                            System.out.println("十字--touch  LR--touch");                        }else {                            System.out.println("是不是这里LR--touch");                        }                    }                }            }传进去的是11 照理说最后输出应该是 十字一定key LR touch 可是最后偏偏输出的是 是不是这里LR--touch 上边if中输出的a[2] 输出也是1 啊 为什么在if判断中直接给跳过了呢 这是怎么回事啊 还有我在if(a[1]==1)的else改成 else if(a[1]==0) 这段代码就不会执行else if(a[1]==0)这一句 直接停止了
查看完整描述

1 回答

?
当年话下

TA贡献1890条经验 获得超9个赞

把所有a[x]==1的比较改为a[x]=='1'1'1'不是一回事。


查看完整回答
反对 回复 2019-04-17
  • 1 回答
  • 0 关注
  • 360 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号