Good evening,
I am fairly new to Java and I am currently taking a class in the field. My assignment is to generate 6 unique random numbers using a "Do While" expression. I might be mistaken but doesnt the inner loop execute first and then it works its way out? With this logic I believe my code should work but then again its not. Please help me if you can. Here is my code:
public class DoLottery
{
public static void main (String args[])
{
int max= 10;
int random;
int random2;
int random3;
int random4;
int random5;
int random6;
do{
random= (int)((Math.random()*max)+1);
do{
random2= (int)((Math.random()*max)+1);
do{
random3= (int)((Math.random()*max)+1);
do{
random4= (int)((Math.random()*max)+1);
do{
random5= (int)((Math.random()*max)+1);
random6= (int)((Math.random()*max)+1);
}while(random6 == random5);
System.out.println(random5);
System.out.println(random6);
}while(random4 == random5 && random4 == random6);
System.out.println(random4);
}while(random3 == random4 && random3 == random5 && random3 == random6);
System.out.println(random3);
}while(random2 == random3 && random2 == random4 && random2 == random5 && random2 == random6);
System.out.println(random2);
}while(random == random2 && random == random3 && random == random4 && random == random5 && random == random6);
System.out.println(random);
//System.out.println(random);
//System.out.println(random2);
//System.out.println(random3);
//System.out.println(random4);
//System.out.println(random5);
//System.out.println(random6);
Again, I am a newbie so be gentle....sidenote: I originally had output at the end but decided to comment it out to see if code would execute if I placed it every time the test was true.
Thanks