title: I am trying out to do the "Count Reverse Pairs" and I can't understand why parentesis() are necessary on this line
body: <p>I know that addition is commutative therefore I want to perform a storing operation with shorthand operation <code>+=</code> at line 46 but the answer differs only when I put the parenthesis, also when when I don't put parenthesis I get wrong answer.</p>
  <p>The line is in the merge function.</p>
  <p>CODE:</p>
  <pre class="lang-java prettyprint-override"><code>public class ProblemA {
  
      public static void main(String[] args) {
          ArrayList&lt;Integer&gt; arr = new ArrayList&lt;Integer&gt; (Arrays.asList(1, 3, 2, 3, 1));
          int n = arr.size();
          //calling mergesort 
          int total = countPair(arr, n);
          System.out.println(total);
      }
  
      public static int countPair(ArrayList&lt;Integer&gt; arr, int n) {
          int total = mergeSort(arr, 0, n - 1);
          return total;
      }
  
      public static int mergeSort(ArrayList&lt;Integer&gt; arr, int low, int high) {
          //termination condition
          if (low &gt;= high) return 0;
          //firstly we'll disassociate the elements of array on elementary level
          int mid = (low + high) / 2;
          //we'll store our count value inside the counter variable 
          int inv = mergeSort(arr, low, mid);
          inv += mergeSort(arr, mid + 1, high);
          inv += merge(arr, low, mid, high);
          return inv;
      }
      public static int merge(ArrayList&lt;Integer&gt; arr, int low, int mid, int high) {
          //AIM: make a double loop and traverse through the elements and increase the right side pointer
          //whenever condition (arr[i]&gt;2*arr[j] is satisfied)
          //int i = 0;
          int total = 0;
          int j = mid + 1;
          for (int i = low; i&lt;= mid; i++) {
              //looping till we run out the right hand side or condition is not satisfied
              while (j&lt;= high &amp;&amp; arr.get(i) &gt; 2 * arr.get(j)) {
                  j++;
              } **
              * total += (j - (mid + 1)); ** * //parenthesis error here
          }
  
          //Now we can move to merging part
          ArrayList&lt;Integer&gt; temp = new ArrayList&lt;Integer&gt; ();
          int left = low, right = mid + 1;
          while (left&lt;= mid &amp;&amp; right&lt;= high) {
              if (arr.get(left)&lt;= arr.get(right)) {
                  temp.add(arr.get(left++));
              } else {
                  temp.add(arr.get(right++));
              }
          }
  
          //for the last right or left remaining element 
          while (left&lt;= mid) {
              temp.add(arr.get(left++));
          }
          while (right&lt;= high) {
              temp.add(arr.get(right++));
          }
  
          //now we can copy the remaining elements from temp list to arr
          for (int i = low, k = 0; i&lt;= high; i++) {
              arr.set(i, temp.get(k++));
          }
          return total;
      }
  }
  </code></pre>
  <p>OUTPUT(with parenthesis) &quot;total += (j-(mid+1))&quot;:</p>
  <pre><code>2
  </code></pre>
  <p>OUTPUT(without parenthesis) &quot;total += j-mid+1&quot;:</p>
  <pre><code>16
  </code></pre>