title: Head First Java: Target Random number is always zero
body: <p>I have been trying this code and the target number generated using math.random() always comes out to be zero. Is there any problem with the code? Please help. I tried a number of times, but every time i try the target random number is always zero.</p>
  
  <pre><code>public class Player {
      int number;
  
      public void guess()
      {
          number = (int) (Math.random()*10);
      }
  }
  
  
  
  public class GuessGame {
  Player p1;
  Player p2;
  Player p3;
  
  public void startGame()
  {
      p1 = new Player();
      p2 = new Player();
      p3 = new Player();
  
      int targetNumber; 
      targetNumber = (int) Math.random() * 10 ;
      System.out.println("The target number is "+ targetNumber);
  
  
      while(true)
      {
          p1.guess();
          p2.guess();
          p3.guess();
  
          int guessp1 = p1.number;
          int guessp2 = p2.number;
          int guessp3 = p3.number;
  
          System.out.println("Number guessed by player p1 is "+ guessp1);
          System.out.println("Number guessed by player p2 is "+ guessp2);
          System.out.println("Number guessed by player p3 is "+ guessp3);
  
          boolean isp1 = false;
          boolean isp2 = false;
          boolean isp3 = false;
  
          if(targetNumber==guessp1)
              isp1 = true;
          if(targetNumber==guessp2)
              isp2 = true;
          if(targetNumber==guessp3)
              isp3 = true;
          if(isp1||isp2||isp3)
          {
              System.out.println("player1 got it right? " + isp1);
              System.out.println("player2 got it right? " + isp2);
              System.out.println("player3 got it right? " + isp3);
              System.out.println("Game Over!!!");
              break;
          }
          else
          {
              System.out.println("All Wrong!! Play Again..");
          }
      }
  
  }
  
  }
  
  public class GameLauncher {
      public static void main(String[] args)
      {
          GuessGame game = new GuessGame();
          game.startGame();
      }
  }
  </code></pre>