title: Java - AND operator not working
body: <p>newbie here,<br>
  I have two variables which generate random numbers through <code>.Random</code>. I want them keep rolling until both variables generate two different values, simultaneously. Therefore, I'm using <code>while</code> loop with <code>&amp;&amp;</code> for this purpose. As I have understood, please correct me if I'm wrong, the line <code>while ((diceRolled1 != 5) &amp;&amp; (diceRolled2 != 4))</code> translates as, keep rolling until the values of <code>diceRolled1</code> <em>is not equal to 5</em> <strong>AND</strong> <code>diceRolled2</code><em>is not equal to 4</em>. But the program ends if either variable matches its value (diceRolled1 = 5 <strong>OR</strong> diceRolled2 = 4). This is not what <code>&amp;&amp;</code> is supposed to do, right? I have ran the code like 10s of times, but not a single time it generated 5 and 4 at the same time. </p>
  
  <p>I also tried <code>==</code>on both sides and either side, but in that case the program didn't run at all, nor it gave any error.</p>
  
  <p>Your help will be much appreciated. Thanks  </p>
  
  <pre><code>import java.util.Random;
  import static java.lang.System.out;
  
  public class DiceRoller {
  public static void main(String[] args) {
      Random dice1 = new Random();
      Random dice2 = new Random();        //Removing this doesn't work either
  
      int diceRolled1 = 0;
      int diceRolled2 = 0;
  
      while ((diceRolled1 != 5) &amp;&amp; (diceRolled2 != 4)) { //&amp; didn't work either 
          diceRolled1 = dice1.nextInt(6) + 1;
          diceRolled2 = dice2.nextInt(6) + 1;
          out.println(diceRolled1 + " " + diceRolled2);
      }
      out.println("Program ends");
  }
  }
  </code></pre>