View Single Post
  #3 (permalink)  
Old 08-07-2007, 04:10 PM
silverq_82 silverq_82 is offline
Member
 
Join Date: Aug 2007
Posts: 8
silverq_82 is on a distinguished road
Hi,

thanks for the reply. I guessed i missed out some important points. Please ignore the part where it gives the hint 'higher' or 'lower'. What I need to do is to create a scenario where the user inputs 5 random number from 1-9. After which, there has to be a comparison between the random generated unique numbers and user's input. Hints on the wrong positions and right positions are also to be stated.

Code:
private static void newGame() throws IOException { final int TOTAL_GUESS = 10; //total number of guesses int guess; //number of guesses int playerGuess; //player's guess boolean correctTry=false; //signal for correct guess String input; //input text data //int correctPos=0; //counts the correct position //int rightNum; //counts the right number //Buffered reader to read console input BufferedReader console = new BufferedReader (new InputStreamReader(System.in)); Scanner myScanner = new Scanner (System.in); //Random generator Random gen = new Random(); int num = gen.nextInt(9) + 1; //Generate 5 non-duplicate numbers hidden from user int mixcount=1; int setcount=5; //mutator values int[] numbers = new int[5]; //declare and create array Random mix = new Random(); for(int i = 0 ; i< numbers.length; i++) { boolean diff = false; while (!diff) { numbers[i] = mix.nextInt(9); diff=true; for (int j=0 ; j < i ; j++) { if (numbers[i]==numbers[j]) { diff = false; break; } } } System.out.print(numbers[i]+" "); //remove this after all is complete } //Player's input but only guessing 1 number how to guess 5 numbers in an array? guess = 0; while(guess < TOTAL_GUESS) { System.out.println("Guess " + guess); System.out.print("Enter five numbers (1 to 9): "); input = console.readLine(); playerGuess = Integer.parseInt (input); if (playerGuess==num) { correctTry=true; break; // break out of the while loop }

Last edited by silverq_82 : 08-07-2007 at 06:11 PM.
Reply With Quote