So I need to generate 5 number and in this 5 number, one of the number must match the number I'm looking for. Let say the number is "1". I generate one number at a time but there must be a "1" by or before the 5th number. The problem with my code is that it continue to loop until "1" is found. Thanks

Code :

for (int counter = 1; counter <= 2; counter++) { int randNum1 = 0; int bottleCapNum = 0; while (randNum1 != 1) { randNum1 = randNum.nextInt(5); bottleCapNum++; } wins++; outFile.println(bottleCapNum); }