5
public class AndOperator {

    public static void main(String[] arg) {
        int value = 8;
        int count = 10;
        int limit = 11;

        if (++value % 2 == 0 && ++count < limit) {
            System.out.println("here");
            System.out.println(value);
            System.out.println(count);
        } else{
            System.out.println("there");
            System.out.println(value);
            System.out.println(count);
        }
    }
}

私は次のように出力されています

there
9
10

count が 10 である理由を説明してください....?

4

4 に答える 4

4

++value= 9 so ++value % 2 == 0is falseso++count < limitは評価されません。

これを短絡評価と呼びます。ウィキペディアのページを参照してください: http://en.wikipedia.org/wiki/Short-circuit_evaluation

于 2013-09-03T19:16:18.527 に答える