title: Making a lottery application: fill array with random numbers
body: <p>I am making a lottery application in Java. My problem is that I think everything is in place and it (the IDE) is telling me that "<code>int lotteryNumbersCount = Eck_LotteryClass.getLotteryNumbers().length;</code>" needs to be static. So I change it to a static int and then I have to change it again in my class. Problem is when I finally run it I get all 0's for my random lottery data. Please help me find the errors in my ways. Total newb here and I've been looking online here but I want to try to figure it out without just copying code somewhere. </p>
  
  <p><strong>Eck_LotteryClass</strong> </p>
  
  <pre><code>import java.util.Random;
  
  
  
  public class Eck_LotteryClass {
  //instance field
  private  int lotteryNumbers [];
  
  
  //Create random lottery numbers method array
  public  int [] getRandomNumbers(){
      lotteryNumbers = new int [5];
      Random r = new Random();
      for(int i = 0; i &lt; 5; i++)
          lotteryNumbers[i] = r.nextInt(10);
  
      return lotteryNumbers;
  }
  
  
  
  public int compareNumbers(int[] usersNumbers) {
  
              int matchedNums = 0;
              if (usersNumbers.length == lotteryNumbers.length) {
                  for (int i = 0; i &lt; lotteryNumbers.length; i++) {
              if (usersNumbers[i] == lotteryNumbers[i]) {
                  matchedNums ++;
                      }
                  }
              }
  
              return matchedNums;}
  
  // Display the random lottery numbers for the user
  public int [] getLotteryNumbers() {
      return lotteryNumbers;
  }
  
  
  
  
  }
  </code></pre>
  
  <p><strong>Eck_LotteryTester</strong></p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Arrays;
  
  
  public class Eck_LotteryTester{
  
  public static void main(String[] args) {
  
      Eck_LotteryClass lottery = new Eck_LotteryClass();
  
      int lotteryNumbersCount = Eck_LotteryClass.getLotteryNumbers().length;
  
      System.out.println("The Pennsylvania Lottery\n");
      System.out.println("There are " + lotteryNumbersCount
              + " numbers in my lottery, they are 0 through 9. "
              + "See if you can win big CASH prizes!!!\n");
  
      // Asks the user to enter five numbers.
      Scanner keyboard = new Scanner(System.in);
      int numbers[] = new int[lotteryNumbersCount];
  
      for (int index = 0; index &lt; numbers.length; index++) {
          System.out.print(String.format("Enter Number %d: ", index + 1));
          numbers[index] = keyboard.nextInt();
      }
  
      // Display the number of digits that match the randomly generated
      // lottery numbers.
  
      int match = lottery.compareNumbers(numbers);
  
      if (match == lotteryNumbersCount) {
  
          // If all of the digits match, display a message proclaiming the
          // user a grand prize winner.
          System.out.println("\nYOU WIN, GO SEE D. LEETE FOR YOUR GRAND PRIZE!!!");
  
      } else {
  
          System.out.println("\nThe winning numbers are " +  Arrays.toString(Eck_LotteryClass.getLotteryNumbers()) + 
                  "\nYou matched " + match + " number(s).");
  
      }
  
    }
  }
  </code></pre>