Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. Basic loop issue

I'm new to java programming and I can't figure out how to get this program to do what I want. This is a basic lottery program that asks for 3 numbers between 10 and 99 and then generates three random values to compare to the inputted values. I can't figure out how to successfully compare the random values to the user defined numbers. The program always says "Congratulations you won!" followed by "I'm sorry you didn't win." Any help would be greatly appreciated. The final section of code is:

```public void randomNumbers()
{
//choose random values for lottery numbers
Random rand = new Random();

int pick1 = rand.nextInt(90)+ 10;
System.out.println("The first lottery number is: " + pick1);

int pick2 = rand.nextInt(90)+ 10;
System.out.println("The second lottery number is: " + pick2);

int pick3 = rand.nextInt(90)+ 10;
System.out.println("The third lottery number is: " + pick3);

//compare to entered numbers and print results

System.out.println("Your numbers were: " + a+", " + b+", " + c);
System.out.println("The winning numbers are: " +pick1+", " +pick2+", " +pick3);

if (((a== pick1)||(a== pick2)||(a== pick3)) && ((b== pick1)||(b== pick2)||(b== pick3))&&((c== pick1)||(c== pick2)||(c== pick3)));
{ System.out.println("CONGRATULATIONS YOU WON!!! ");

}else
System.out.println("I'm sorry you did not win.");

}```

2. Re: Basic loop issue

Hello Nismoz3255, welcome to the Java Programming Forums.

You have a problem with your if statement. At the end if the if statement you have ;
Removing this should make it work as expected.

```	    	 if (((a== pick1)||(a== pick2)||(a== pick3)) && ((b== pick1)||(b== pick2)||(b== pick3))&&((c== pick1)||(c== pick2)||(c== pick3)))
{
System.out.println("CONGRATULATIONS YOU WON!!! ");
}else
{
System.out.println("I'm sorry you did not win.");
}```

3. Re: Basic loop issue

Haha wow I completely missed that. Thanks so much.

No problem