title: Why is my program only doing the else statement on one of the if statements
body: <p>I want my code to make sure that all the if statements work, and if one of them doesn't work, it should put that that specific one is incorrect and not show the IP address part. right now when I'm doing it, it only works on the 4th one. the other ones say that it is incorrect but still put the IP address.</p>
  <pre class="lang-java prettyprint-override"><code>{
      Scanner scan = new Scanner(System.in);
  
      System.out.println(&quot;Please enter the first octet:&quot;);
      int a = scan.nextInt();
      System.out.println(&quot;Please enter the second octet:&quot;);
      int b = scan.nextInt();
      System.out.println(&quot;Please enter the third octet:&quot;);
      int c = scan.nextInt();
      System.out.println(&quot;Please enter the fourth octet:&quot;);
      int d = scan.nextInt();
  
      if (!(a &gt;= 0 &amp;&amp; a &lt;= 255))
      {
          System.out.println(&quot;Octet 1 is incorrect&quot;);
      }
      if (!(b &gt;= 0 &amp;&amp; b &lt;= 255))
      {
          System.out.println(&quot;Octet 2 is incorrect&quot;);
      }
      if (!(c &gt;= 0 &amp;&amp; c &lt;= 255))
      {
          System.out.println(&quot;Octet 3 is incorrect&quot;);
      }
      if (!(d &gt;= 0 &amp;&amp; d &lt;= 255))
      {
          System.out.println(&quot;Octet 4 is incorrect&quot;);
      }
  
      else
      {
          System.out.println(&quot;IP Address:&quot; + a + &quot;.&quot; + b + &quot;.&quot; + c + &quot;.&quot; + d);
      }
  }
  </code></pre>