Advertisement
brilliant_moves

ArrayListLotto.java

Oct 1st, 2012
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.94 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Random;
  4.  
  5. public class ArrayListLotto {
  6.  
  7.     /** Program: ArrayListLotto.java
  8.     *   Purpose: Lotto program uses Array List
  9.     *   Creator: Chris Clarke
  10.     *   Created: 09.08.2012
  11.     */
  12.  
  13.     public static void main(String[] args) {
  14.         ArrayList<Integer> arl = new ArrayList<Integer>();
  15.         int[] chosen = new int[SELECTIONS];
  16.  
  17.         for (int index=0; index<SIZE; index++) {
  18.             arl.add(new Integer(index+1));
  19.         }
  20.  
  21.         Random ran = new Random();
  22.  
  23.         for (int i=0; i<SELECTIONS; i++) {
  24.             int selection = ran.nextInt(arl.size());
  25.             chosen[i] = arl.get(selection);
  26.             // remove so it can't get chosen again
  27.             arl.remove(selection);
  28.         }
  29.  
  30.         Arrays.sort(chosen);
  31.  
  32.         System.out.print("Here are your random lotto numbers: ");
  33.         for (int i=0; i<SELECTIONS; i++) {
  34.             System.out.print(chosen[i] + " ");
  35.         }
  36.     }
  37.  
  38.     public static final int SIZE = 49;
  39.     public static final int SELECTIONS = 6;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement