Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>An <code>if</code> statement is of the form:</p> <pre><code>if (condition) statement </code></pre> <p>You've currently got <em>two</em> bracketed conditions... which also end up <em>assigning</em> values, which probably isn't what you want.</p> <p>So first fix to get it to compile:</p> <pre><code>if ((First_Relation = true) &amp; (Second_Relation = true)) </code></pre> <p>Then change the assignments to equality checks, as otherwise it will simply assign <code>true</code> to both variables and the condition will pass regardless of their previous values:</p> <pre><code>if ((First_Relation == true) &amp; (Second_Relation == true)) </code></pre> <p>Then remove comparisons with boolean constants:</p> <pre><code>if ((First_Relation) &amp; (Second_Relation)) </code></pre> <p>Then remove unnecessary brackets:</p> <pre><code>if (First_Relation &amp; Second_Relation) </code></pre> <p>Then make the variables follow Java naming conventions:</p> <pre><code>if (firstRelation &amp; secondRelation) </code></pre> <p>Then use the more conventional <code>&amp;&amp;</code> instead of <code>&amp;</code> - <code>&amp;&amp;</code> is short-circuiting, and is almost always what you want:</p> <pre><code>if (firstRelation &amp;&amp; secondRelation) </code></pre> <p>Now you've still got a semi-colon directly after your <code>if</code> condition, which makes it pointless - it will <em>always</em> execute the <code>System.out.println</code> statement, because that's not part of the <code>if</code> statement. You <em>could</em> just remove the semi-colon, but I'd add braces for clarity:</p> <pre><code>if (firstRelation &amp;&amp; secondRelation) { System.out.println("insert text here"); } </code></pre> <p>Next, note that you're only actually initializing your variables if the condition is true - so you'll currently get a compile-time error for trying to read variables which aren't definitely assigned.</p> <p>First, fix the definite assignment:</p> <pre><code>// Names changed to follow conventions boolean firstRelation = p &gt; q; boolean secondRelation = r &lt; s; </code></pre> <p>... and the code above should be fine.</p> <p>Next, spot that you're really gaining very little indeed from those extra variables. Inline the conditions instead:</p> <pre><code>if (p &gt; q &amp;&amp; r &lt; s) { System.out.println("Given the values for p,q,r, and s the expression " + "(p &gt; q) &amp;&amp; !(r &lt; s) evaluates to "; } </code></pre> <p>At this point, it becomes very clear that there's a further bug - because your message talks about <code>!(r &lt; s)</code> but the condition is just <code>r &lt; s</code>. So you need to decide what you want to achieve, and make the code and the message reflect the same thing. Note that you don't finish the message, either. Indeed, you could simplify the whole thing to:</p> <pre><code>System.out.println("Given the values for p,q,r, and s the expression " + "(p &gt; q) &amp;&amp; !(r &lt; s) evaluates to " + ((p &gt; q) &amp;&amp; !(r &lt; s)); </code></pre> <p>... or whatever you want the expression to actually be.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload