Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Imports
- import java.util.Random;
- public class LotteryProgram
- {
- public static void main(String[] args)
- {
- int[] combo = {0, 0, 0, 0, 0, 0};
- Random lotteryBall = new Random();
- for (int currentNum = 0; currentNum < 6; currentNum++) { // For Each Number
- combo[currentNum] = lotteryBall.nextInt(49)+1;
- for (int checkDuplicate = currentNum - 1; checkDuplicate >= 0; checkDuplicate--) { // Check For Duplicates
- while (combo[currentNum] == combo[checkDuplicate]) { // Run a Change, Reset Duplicate Check
- combo[currentNum] = lotteryBall.nextInt(49)+1;
- // System.out.println("Changed Spot " + (x+1)); // Tell Duplicate
- checkDuplicate = currentNum - 1;
- }
- }
- }
- // Print Combination
- System.out.println("Combination: ");
- for (int x = 0; x < 6; x++)
- {
- System.out.print(combo[x] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment