Java如何计算如果语句返回true的次数

for (int i = 0; i < 1000; i++) {

            //Statement

            int count = 0;

            if (ResultABinary.equals(ResultBBinary)) {

                count++;

                System.out.println(count);

            }

            // System.out.println(count);

        }

在这段代码中,我得到计数 1 1 1,如果我打印出注释计数,我得到 997 次 0,我该怎么做才能使我的 println 为 3?简而言之,我想计算如果语句返回 true 并打印出该数字的次数


哔哔one
浏览 160回答 2
2回答

慕斯709654

int count = 0;&nbsp; &nbsp;&nbsp;for (int i = 0; i < 1000; i++) {&nbsp; &nbsp; //Statement&nbsp; &nbsp; if (ResultABinary.equals(ResultBBinary)) {&nbsp; &nbsp; &nbsp; &nbsp; count++;&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(count);&nbsp; &nbsp; }}System.out.println(count);

开心每一天1111

static int count = 0;for (int i = 0; i < 1000; i++) {&nbsp; &nbsp; //Statement&nbsp; &nbsp; if (ResultABinary.equals(ResultBBinary)) {&nbsp; &nbsp; &nbsp; &nbsp; count++;&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(count);&nbsp; &nbsp; }}System.out.println(count);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java