# Stuck with loops

• 05-15-2011, 07:11 PM
sillyben
Stuck with loops
Can anyone help me with this problem,
'You should reject numbers which has already been guessed whether correct or not. '
I have asked the user to input in the number, but when i want to stop them from re-entering the same number, i seems to have a problem.
What function can i use?
• 05-15-2011, 07:43 PM
Fubarable
You must have some type of collection of numbers that have already been guessed, so why not loop through that collection checking to see if the current number is amongst the already guessed ones.
• 05-15-2011, 07:45 PM
sillyben
How do i do that?
i have done till here:

Code:

```// Player input                 int[] arrayPlayerGuess = new int[3];                 for (int i = 0; i < arrayPlayerGuess.length; i++) {                         number = Keyboard.readInt("Enter Your Guess Number > ");                         // Points                         for (int a = 0; a < arrayRandomNumber.length; a++) {                                 if (number == arrayRandomNumber[a]) {                                         count = count + 1;                                 }                         }                         // End of points                         // End of player input                         {                                 // Validation                                 while (number <= 0 || number > 50) {                                         System.out.println("Please Only Enter Number 1 To 50.");                                         number = Keyboard.readInt("Enter Your Guess Number > ");                                         // End of validation                                 }                         }                 }```
how do i add to this code?
• 05-15-2011, 08:49 PM
JosAH
Quote:

Originally Posted by sillyben
Can anyone help me with this problem,
'You should reject numbers which has already been guessed whether correct or not. '
I have asked the user to input in the number, but when i want to stop them from re-entering the same number, i seems to have a problem.
What function can i use?

Read the API documentation of the BitSet class; it is cheap and fast. If you generate/guess a number, check its bit; it it was already set, the number was already generated/guessed, otherwise set its bit to mark it generated/set.

kind regards,

Jos