Is the left-to-right order of operations guaranteed in Java?

后端 未结 10 1216
温柔的废话
温柔的废话 2021-01-04 10:16

Consider this function:

public static final int F(int a, int b) {
    a = a - 1 + b;
    // and some stuff
    return a;
}

Is it required

10条回答
  •  伪装坚强ぢ
    2021-01-04 10:51

    Yes, although the bigger question is does it really matter? Subtraction and addition have the same precedence in any scientific mathematical operation and are commutable. That is:

    x = input - 1 + q;

    is the same as

    x = input + q - 1;

提交回复
热议问题