Results 1 to 4 of 4
  1. #1
    sillyben is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default 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?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    sillyben is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    How do i do that?
    i have done till here:

    Java 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?
    Last edited by Fubarable; 05-15-2011 at 08:50 PM. Reason: code tags added

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by sillyben View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 20
    Last Post: 03-22-2011, 04:02 AM
  2. I'm stuck help!!!
    By nobody58 in forum Advanced Java
    Replies: 2
    Last Post: 03-18-2010, 02:52 PM
  3. Stuck in sea
    By programmer_007 in forum JDBC
    Replies: 1
    Last Post: 09-17-2009, 04:00 AM
  4. Im on my last lab!!!! And im stuck...:(
    By clanboru15 in forum New To Java
    Replies: 5
    Last Post: 03-13-2009, 01:44 AM
  5. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 02:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •