This is my first program apart from the infamous "HelloWorld" one. The purpose of this program is to simulate a lottery number generator. The program is printing numbers which is great, but it isn't behaving like how it should. It's supposed to print 100 number combinations and it only prints 1 to approximately 8-10. It looks like it's stuck in a loop somewhere? Also, I'm not sure if my syntax is correct in relation to the "breaks" on the loops and so forth. Lastly, when I run it in the CMD prompt the cursor doesn't go back to the C:\ root after the program has executed. Again, this is why I think it's stuck in a loop. Any comments will be much appreciated.
/*
* 02-16-2013
* This program is for selecting 100 random number combinations for the Powerball lottery. Each number combination contains six separate numbers.
* If it works correctly it should automatically display 100 number combinations.
*/
import java.util.Random;
public class Lotto2 {
public Lotto2() {
// The range for the first five numbers is 1-59.
int firstNumber;
int secondNumber;
int thirdNumber;
int fourthNumber;
int fifthNumber;
// The range for the sixth number is 1-35.
int sixthNumber;
Random rand = new Random();
firstNumber = rand.nextInt(59) + 1; //How I got the range: 59-1+1=59 which translates to (59) + 1.
secondNumber = rand.nextInt(59) + 1;
thirdNumber = rand.nextInt(59) + 1;
fourthNumber = rand.nextInt(59) + 1;
fifthNumber = rand.nextInt(59) + 1;
sixthNumber = rand.nextInt(35) + 1;
int a = firstNumber;
int b = secondNumber;
int c = thirdNumber;
int d = fourthNumber;
int e = fifthNumber;
// Testing firstNumber so that "a != b,c,d,e" Note: At first I tried if(a != b,c,d,e){ ... }, but it wouldn't work?
while (a == b || a == c || a == d || a == e) { // && and, || or
for (int i = a; i == b; i++){
i = rand.nextInt(59) + 1;
if (a != b){ break;
} }
for (int i2 = a; i2 == c; i2++){
i2 = rand.nextInt(59) + 1;
if (a != c){ break;
} }
for (int i3 = a; i3 == d; i3++){
i3 = rand.nextInt(59) + 1;
if (a != d){ break;
} }
for (int i4 = a; i4 == e; i4++){
i4 = rand.nextInt(59) + 1;
if (a != e){ break;
} }
}
// Testing secondNumber so that "b != a,c,d,e"
while (b == a || b == c || b == d || b == e) {
for (int i = b; i == a; i++){
i = rand.nextInt(59) + 1;
if (b != a){ break;
} }
for (int i2 = b; i2 == c; i2++){
i2 = rand.nextInt(59) + 1;
if (b != c){ break;
} }
for (int i3 = b; i3 == d; i3++){
i3 = rand.nextInt(59) + 1;
if (b != d){ break;
} }
for (int i4 = b; i4 == e; i4++){
i4 = rand.nextInt(59) + 1;
if (b != e){ break;
} }
}
//Testing thirdNumber so that "c != a,b,d,e"
while (c == a || c == b || c == d || c == e) {
for (int i = c; i == a; i++){
i = rand.nextInt(59) + 1;
if (c != a){ break;
} }
for (int i2 = c; i2 == b; i2++){
i2 = rand.nextInt(59) + 1;
if (c != b){ break;
} }
for (int i3 = c; i3 == d; i3++){
i3 = rand.nextInt(59) + 1;
if (c != d){ break;
} }
for (int i4 = c; i4 == e; i4++){
i4 = rand.nextInt(59) + 1;
if (c != e){ break;
} }
}
//Testing fourthNumber so that "d != a,b,c,e"
while (d == a || d == b || d == c || d == e) {
for (int i = d; i == a; i++){
i = rand.nextInt(59) + 1;
if (d != a){ break;
} }
for (int i2 = d; i2 == b; i2++){
i2 = rand.nextInt(59) + 1;
if (d != b){ break;
} }
for (int i3 = d; i3 == c; i3++){
i3 = rand.nextInt(59) + 1;
if (d != c){ break;
} }
for (int i4 = d; i4 == e; i4++){
i4 = rand.nextInt(59) + 1;
if (d != e){ break;
} }
}
//Testing fifthNumber so that "e != a,b,c,d"
while (e == a || e == b || e == c || e == d) {
for (int i = e; i == a; i++){
i = rand.nextInt(59) + 1;
if (e != a){ break;
} }
for (int i2 = e; i2 == b; i2++){
i2 = rand.nextInt(59) + 1;
if (e != b){ break;
} }
for (int i3 = e; i3 == c; i3++){
i3 = rand.nextInt(59) + 1;
if (e != c){ break;
} }
for (int i4 = e; i4 == d; i4++){
i4 = rand.nextInt(59) + 1;
if (e != d){ break;
} }
}
System.out.println(a + " " + b + " " + c + " " + d + " " + e + " " + "/" + " " + sixthNumber);
}
public static void main (String[] args){
for (int i = 0; i < 100; i++){ // This should make it print 100 lottery numbers that contain six separate numbers in each.
Lotto2 lot = new Lotto2();
}
}
}