Last active
December 25, 2015 17:18
-
-
Save imryan/7011708 to your computer and use it in GitHub Desktop.
Generates random lottery numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Lottery | |
| { | |
| public static void main (String[] args) | |
| { | |
| // Create an ArrayList of integers to store the 6 random numbers | |
| ArrayList<Integer> numbers = getLotteryNumbers(); | |
| // Print the results | |
| System.out.println("Pick these numbers: " + numbers); | |
| } | |
| public static ArrayList<Integer> getLotteryNumbers() | |
| { | |
| // Create a new random number generator & ArrayList of integers | |
| Random generator = new Random(); | |
| ArrayList<Integer> numbers = new ArrayList<Integer>(); | |
| // Loop 6 times & get 6 random numbers | |
| for (int i = 0; i < 6; i++) | |
| { | |
| numbers.add(generator.nextInt(49)); | |
| } | |
| return numbers; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment