猿问

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

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


Smart猫小萌
浏览 362回答 1
1回答

当年话下

把所有a[x]==1的比较改为a[x]=='1',1和'1'不是一回事。
随时随地看视频慕课网APP

相关分类

Java
我要回答