title: Comparing three numbers with the Java logical-ternary operator?
body: <p>I'm trying to create a method that returns the smallest value of three values (all bytes). Here is what I have:</p>
  
  <pre><code>public static byte findSmallestOfThree(byte n1, byte n2, byte n3) {
      return n1 &gt; n2 ? n2 : n1 &gt; n3 ? n3 : n1;
  }
  </code></pre>
  
  <p>Now, the issue I'm having is that it doesn't always work.</p>
  
  <p>Here are some inputs, and the outputs:</p>
  
  <pre><code>9, 10, 11 -&gt; 9
  
  10, 9, 11 -&gt; 9
  
  10, 11, 9 -&gt; 9
  
  11, 10, 9 -&gt; 10
  </code></pre>
  
  <p>As you can see, when I entered 11, 10, 9 (in that order), I got 10 as the result (even though it should have been 9).</p>
  
  <p>What is wrong with my logic? I think I've messed something up with the ternary operators, but I'm not sure what it is...</p>