jeudi 5 janvier 2017

In Java, why does the output of b does not change in the case? Is it possible that the using of "or" lets it only judge the first case?

Here is the code and i'm really confusing about the output.

public static void main(String[] args) {
    int a = 1;
    int b = 1;

    for (int c = 0; c < 5; c++) {
        if ((++a > 2) || (++b > 2)) {
            a++;

        }
    }
    System.out.println(a + " " + b);
}

The output is 10 2

However, why could a always change but b remains the same?

Aucun commentaire:

Enregistrer un commentaire