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

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

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)这一句 直接停止了


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

【热门文章】
【热门文章】