title: How do math equations work in Java?
body: <p>When I do something like this</p>
  
  <pre><code>int test = 5 + 3 * (4 - 1) / 2;
  </code></pre>
  
  <p>I get 9. I suspected this was because int rounds down. However, when I do this</p>
  
  <pre><code>float test = 5 + 3 * (4 - 1) / 2;
  </code></pre>
  
  <p>I also get 9. However, when I do this</p>
  
  <pre><code>float test1 = 5;
  float test2 = 4.5;
  float test = test1 + test2;
  </code></pre>
  
  <p>Test finally outputs 9.5. Could someone explain the logic behind this? Why don't I get 9.5 in the second example? Thanks.</p>