开发者社区> 问答> 正文

关于位运算的判断问题

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

展开
收起
蛮大人123 2016-03-11 11:03:18 2348 0
2 条回答
写回答
取消 提交回答
  • 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)这一句 直接停止了
    2019-07-17 18:58:43
    赞同 展开评论 打赏
  • 我说我不帅他们就打我,还说我虚伪

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

    2019-07-17 18:58:42
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载