title: Java ternary operator precedence ? Different outputs given
body: <p>I have the below code producing this output (<strong>no space after -1</strong>) ==> <code>"1 3 -14 -15 -1"</code></p>
  
  <pre><code>int [] arr = {1, 3, Integer.MAX_VALUE, 4, Integer.MAX_VALUE, 5, Integer.MAX_VALUE};
  for (int dist : arr) {
      System.out.print((dist == Integer.MAX_VALUE) ? -1 : dist + " ");
  }
  </code></pre>
  
  <p>But if I evaluate the ternary expression separately (as shown below), it gives a different output (what I expected) ==> <code>"1 3 -1 4 -1 5 -1"</code></p>
  
  <pre><code>int [] arr = {1, 3, Integer.MAX_VALUE, 4, Integer.MAX_VALUE, 5, Integer.MAX_VALUE}; 
  for (int dist : arr) {
      int finalDist = (dist == Integer.MAX_VALUE) ? -1 : dist;
      System.out.print(finalDist + " ");          
  }
  </code></pre>
  
  <p>What is going wrong with the first code snippet?</p>