Why does java require a double equals sign?
<p>Why does java require a double equals sign (==) when comparing Integers in a <code>if</code> statement?</p>

<p>For example</p>

<pre><code>if(x = 3.141)
     System.out.println("x is equal to pi.");
</code></pre>

<p>is incorrect, it should be</p>

<pre><code>if(x == 3.141)
     System.out.println("x is equal to pi.");
</code></pre>

<p>I know that "==" is used to compare integers and "=" is used to set an integer value, but why in a <code>if</code> statement does this remain true?</p>

<p>Is it even allowed to assign a variable a value in an <em>if statement</em> (or initiate a new variable)? </p>

<p>Is there any reason anyone would ever want to assign a variable a new value inside an <code>if</code> statement (if so please provide an example)?</p>

<p>This seems like a question that should already have an answer, but I was unable to find one on here or using google, if this is a duplicate question please tell me and I will remove it immediately.</p>
