title: How can you assign a variable a value inside a if statement in Java
body: <p>I need to do something like this,</p>
  
  <pre><code>if (first_var &gt; second_var)
    int difference = first_var - second_var;
  if (first_var &lt; second_var)
    int difference = second_var - first_var;
  </code></pre>
  
  <p>When I try to compile this, an error comes stating the variable 'difference' may not have been initialized. Making the variable 'difference' global doesn't help either. </p>