View Single Post
  #5 (permalink)  
Old 08-08-2007, 07:04 PM
silverq_82 silverq_82 is offline
Member
 
Join Date: Aug 2007
Posts: 8
silverq_82 is on a distinguished road
Hey, thanks for the guidance... Btw, i have another question. I have these set of codes and i want to compare the random generated set of 5 numbers with user's input of 5 numbers. Not sure how to start. I'm stuck after prompting user to key in the 5 numbers. Below are the codes:-

Code:
private static void newGame() throws IOException { //Random generator Random gen = new Random(); int num = gen.nextInt(9) + 1; //Generate 5 non-duplicate numbers within an array int mixcount=1; int setcount=5; int[] numbers = new int[5]; //declare and create array Random mix = new Random(); for(int i = 0 ; i< numbers.length; i++) { boolean diff = false; //generate non-duplicate numbers 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 } InputStreamReader isr = new InputStreamReader( System.in ); //Create an InputStreamReader using the standard input stream BufferedReader stdin = new BufferedReader( isr ); //Create a BufferedReader using the InputStreamReader created System.out.print( "Enter 5 numbers (1 to 9): " ); String input = stdin.readLine(); // Read a line of text from the user
Reply With Quote