Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Random;
- public class ArrayListLotto {
- /** Program: ArrayListLotto.java
- * Purpose: Lotto program uses Array List
- * Creator: Chris Clarke
- * Created: 09.08.2012
- */
- public static void main(String[] args) {
- ArrayList<Integer> arl = new ArrayList<Integer>();
- int[] chosen = new int[SELECTIONS];
- for (int index=0; index<SIZE; index++) {
- arl.add(new Integer(index+1));
- }
- Random ran = new Random();
- for (int i=0; i<SELECTIONS; i++) {
- int selection = ran.nextInt(arl.size());
- chosen[i] = arl.get(selection);
- // remove so it can't get chosen again
- arl.remove(selection);
- }
- Arrays.sort(chosen);
- System.out.print("Here are your random lotto numbers: ");
- for (int i=0; i<SELECTIONS; i++) {
- System.out.print(chosen[i] + " ");
- }
- }
- public static final int SIZE = 49;
- public static final int SELECTIONS = 6;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement