Is multiple && statements allowed in Java?
<p>Is the following code allowed in Java? My program doesn't work unless I comment this line out and I am not sure if the multiple &amp;&amp; statements in the if is allowed.</p>

<pre><code>if(number.isBusy() &amp;&amp; number2.isBusy() &amp;&amp; number3.isBusy() &amp;&amp; number4.isBusy() &amp;&amp; number5.isBusy() ) {}
</code></pre>

<p>Edited to add:
If you comment out the line that is given above, the program will actually display something in  the output window (although the only thing that gets something added to it is "number5") if it is left in, all of the outputs are zero.</p>

<p>This is the entire program right now:</p>

<pre><code>// FILE: Line.java
// This program illustrates the use of the lineSimulate method which uses
// a simple queue to simulate cars waiting at a car wash.

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
// import edu.colorado.simulations.BooleanSource;
// import edu.colorado.simulations.Line ;
// import edu.colorado.simulations.Averager;

/******************************************************************************
* The &lt;CODE&gt;CarWash&lt;/CODE&gt; Java application illustrates the use of
* the &lt;CODE&gt;lineSimulate&lt;/CODE&gt; method.
* The illustration uses the following values:
*   &lt;CODE&gt;
*   &lt;br&gt;lineTime = 240
*   &lt;br&gt;arrivalTime = 0.0025
*   &lt;br&gt;totalTime = 6000
*   &lt;/CODE&gt;
*
* &lt;p&gt;&lt;dt&gt;&lt;b&gt;Java Source Code for this class:&lt;/b&gt;&lt;dd&gt;
*   &lt;A HREF="../applications/CarWash.java"&gt;
*   http://www.cs.colorado.edu/~main/applications/CarWash.java
*   &lt;/A&gt;
*
* @author Michael Main 
*   &lt;A HREF="mailto:main@colorado.edu"&gt; (main@colorado.edu) &lt;/A&gt;
*
* @version
*   Jun 12, 1998
******************************************************************************/
public class LineWait
{
   /**
   * The main method activates &lt;CODE&gt;lineSimulate&lt;/CODE&gt; with the values:
   *   &lt;CODE&gt;
   *   &lt;br&gt;lineTime = 240
   *   &lt;br&gt;arrivalTime = 0.0025
   *   &lt;br&gt;totalTime = 6000
   *   &lt;/CODE&gt;
   * &lt;BR&gt;The &lt;CODE&gt;String&lt;/CODE&gt; argument (&lt;CODE&gt;args&lt;/CODE&gt;) is not used in
   * this implementation.
   **/
   public static void main(String[ ] args)
   {

      final int LINETIME = 100 + (int)(Math.random() * ((400) + 1));
      final double ARRIVALPROB = (Math.random() * ((.1) + 1));
      final int TOTALTIME = 6000;

      lineSimulate(LINETIME, ARRIVALPROB, TOTALTIME);
   }

   /**
   * Simulate the running of a car washer for a specified amount of time.
   * @param &lt;CODE&gt;lineTime&lt;/CODE&gt;
   *   the number of seconds required to wash one car
   * @param &lt;CODE&gt;arrivalProb&lt;/CODE&gt;
   *   the probability of a customer arriving in any second, for example
   *   0.1 is 10%
   * @param &lt;CODE&gt;totalTime&lt;/CODE&gt;
   *   the total number of seconds for the simulation
   * &lt;dt&gt;&lt;b&gt;Precondition:&lt;/b&gt;&lt;dd&gt;
   *   &lt;CODE&gt;lineTime&lt;/CODE&gt; and &lt;CODE&gt;totalTime&lt;/CODE&gt; are positive;
   *   &lt;CODE&gt;arrivalProb&lt;/CODE&gt; lies in the range 0 to 1.
   * &lt;dt&gt;&lt;b&gt;Postcondition:&lt;/b&gt;&lt;dd&gt;
   *   The method has simulated a car wash where &lt;CODE&gt;lineTime&lt;/CODE&gt; is the
   *   number of seconds needed to wash one car, &lt;CODE&gt;arrivalProb&lt;/CODE&gt; is
   *   the probability of a customer arriving in any second, and
   *   &lt;CODE&gt;totalTime&lt;/CODE&gt; is the total number of seconds for the
   *   simulation. Before the simulation, the method has written its three
   *   parameters to &lt;CODE&gt;System.out&lt;/CODE&gt;. After the simulation, the method
   *   has written two pieces of information to &lt;CODE&gt;System.out&lt;/CODE&gt;:
   *   (1) The number of cars washed, and (2) The average waiting time for
   *   customers that had their cars washed. (Customers that are still in the 
   *   queue are not included in this average).
   * @exception java.lang.IllegalArgumentException
   *   Indicates that one of the arguments violates the precondition.
   **/
   public static void lineSimulate
   (int lineTime, double arrivalProb, int totalTime)
   {  
      Queue&lt;Integer&gt; arrivalTimes = new LinkedList&lt;Integer&gt;( ); 
      Queue&lt;Integer&gt; arrivalTimes2 = new LinkedList&lt;Integer&gt;( );  
      Queue&lt;Integer&gt; arrivalTimes3 = new LinkedList&lt;Integer&gt;( );
      Queue&lt;Integer&gt; arrivalTimes4 = new LinkedList&lt;Integer&gt;( );
      Queue&lt;Integer&gt; arrivalTimes5 = new LinkedList&lt;Integer&gt;( );
      int next;
      BooleanSource arrival = new BooleanSource(arrivalProb);
      Line number = new Line(lineTime);
      Line number2 = new Line(lineTime);
      Line number3 = new Line(lineTime);
      Line number4 = new Line(lineTime);
      Line number5 = new Line(lineTime);
      Averager waitTimes = new Averager( );
      Averager waitTimes2 = new Averager();
      Averager waitTimes3 = new Averager();
      Averager waitTimes4 = new Averager();
      Averager waitTimes5 = new Averager();
      int currentSecond;
      // Write the parameters to System.out.
      System.out.println("Seconds to wait in line " + lineTime);
      System.out.print("Probability of customer arrival during a second: ");
      System.out.println(arrivalProb);
      System.out.println("Total simulation seconds: " + totalTime); 

      // Check the precondition:
      if (lineTime &lt;= 0 || arrivalProb &lt; 0 || arrivalProb &gt; 1 || totalTime &lt; 0)
         throw new IllegalArgumentException("Values out of range");        




      for (currentSecond = 0; currentSecond &lt; totalTime; currentSecond++)
      {  // Simulate the passage of one second of time.

         // Check whether a new customer has arrived.
         if (arrival.query( ))
            {
                System.out.println("Test1");
                if(number.isBusy() &amp;&amp; number2.isBusy() &amp;&amp; number3.isBusy() &amp;&amp; number4.isBusy() &amp;&amp; number5.isBusy() )
                {
                   System.out.println("Test2");
                    if(arrivalTimes.size() &lt; arrivalTimes2.size() &amp;&amp; arrivalTimes.size() &lt; arrivalTimes3.size() &amp;&amp; arrivalTimes.size() &lt; arrivalTimes4.size() &amp;&amp; arrivalTimes.size() &lt; arrivalTimes5.size()) 
                    {
                        arrivalTimes.add(currentSecond);
                        System.out.println("Test");
                    }
                    else if(arrivalTimes2.size() &lt; arrivalTimes.size() &amp;&amp; arrivalTimes2.size() &lt; arrivalTimes3.size() &amp;&amp; arrivalTimes2.size() &lt; arrivalTimes4.size() &amp;&amp; arrivalTimes2.size() &lt; arrivalTimes5.size())
                    {
                        arrivalTimes2.add(currentSecond);
                        System.out.println("Test");
                    }
                    else if(arrivalTimes3.size() &lt; arrivalTimes.size() &amp;&amp; arrivalTimes3.size() &lt; arrivalTimes2.size() &amp;&amp; arrivalTimes3.size() &lt; arrivalTimes4.size() &amp;&amp; arrivalTimes3.size() &lt; arrivalTimes5.size())
                    {
                        arrivalTimes3.add(currentSecond);
                        System.out.println("Test");
                    }
                    else if(arrivalTimes4.size() &lt; arrivalTimes.size() &amp;&amp; arrivalTimes4.size() &lt; arrivalTimes3.size() &amp;&amp; arrivalTimes4.size() &lt; arrivalTimes2.size() &amp;&amp; arrivalTimes4.size() &lt; arrivalTimes5.size())
                    {
                        arrivalTimes4.add(currentSecond);
                        System.out.println("Test");
                    }
                    else{arrivalTimes5.add(currentSecond);}
                }

            }

             // Check whether we can put the person into a line.
             if ((!number.isBusy( ))  &amp;&amp;  (!arrivalTimes.isEmpty( )))
             {
                next = arrivalTimes.remove( );
                waitTimes.addNumber(currentSecond - next);
                number.startMoving( );
             }
             if ((!number2.isBusy( ))  &amp;&amp;  (!arrivalTimes2.isEmpty( )))
             {
                next = arrivalTimes2.remove( );
                waitTimes2.addNumber(currentSecond - next);
                number2.startMoving( );
             }
             if ((!number3.isBusy( ))  &amp;&amp;  (!arrivalTimes3.isEmpty( )))
             {
                next = arrivalTimes3.remove( );
                waitTimes3.addNumber(currentSecond - next);
                number3.startMoving( );
             }
             if ((!number4.isBusy( ))  &amp;&amp;  (!arrivalTimes4.isEmpty( )))
             {
                next = arrivalTimes4.remove( );
                waitTimes4.addNumber(currentSecond - next);
                number4.startMoving( );
             }
             if ((!number5.isBusy( ))  &amp;&amp;  (!arrivalTimes5.isEmpty( )))
             {
                next = arrivalTimes5.remove( );
                waitTimes5.addNumber(currentSecond - next);
                number5.startMoving( );
             }


         // Subtract one second from the remaining time in the current li
         number.reduceRemainingTime( );
         number2.reduceRemainingTime( );
         number3.reduceRemainingTime( );
         number4.reduceRemainingTime( );
         number5.reduceRemainingTime( );
        }   




      // Write the summary information about the simulation.
      System.out.println("\nCustomers served Line1: " + waitTimes.howManyNumbers( )); 
      if (waitTimes.howManyNumbers( ) &gt; 0)
         System.out.println("Average wait Line1: " + waitTimes.average( ) + " sec");
         System.out.println("\nCustomers served Line2: " + waitTimes2.howManyNumbers( )); 
      if (waitTimes.howManyNumbers( ) &gt; 0)
         System.out.println("Average wait Line2: " + waitTimes2.average( ) + " sec");
       System.out.println("\nCustomers served Line3: " + waitTimes3.howManyNumbers( )); 
      if (waitTimes.howManyNumbers( ) &gt; 0)
         System.out.println("Average wait Line3: " + waitTimes3.average( ) + " sec");
       System.out.println("\nCustomers served Line4: " + waitTimes4.howManyNumbers( )); 
      if (waitTimes.howManyNumbers( ) &gt; 0)
         System.out.println("Average wait Line4: " + waitTimes4.average( ) + " sec");
          System.out.println("\nCustomers served Line5: " + waitTimes5.howManyNumbers( )); 
      if (waitTimes.howManyNumbers( ) &gt; 0)
         System.out.println("Average wait Line5: " + waitTimes5.average( ) + " sec");

} 
}
</code></pre>
