this code runs succesfully onnet bean, though it compiled in prompt but
compiler is telling me that it is not checked

import java.io.*;         
import java.util.*;
class RandomSelection {




        
    public static void main(String[] args) {    

try{
        FileInputStream  fstream = new FileInputStream("c:\\filea.txt");
    	
         DataInputStream in = new DataInputStream(fstream);
        BufferedReader  br = new BufferedReader(new InputStreamReader(in));
  	LineNumberReader  ln = new LineNumberReader(br);

      	int count = 0;

    	while (ln.readLine() != null){

    		count++;
	}
	ln.close();
	in.close();
     

      
	fstream = new FileInputStream("c:\\filea.txt");

    	in = new DataInputStream(fstream);
        br = new BufferedReader(new InputStreamReader(in));
    	String strLine;
  	ln = new LineNumberReader(br);
        Random mixture = new Random();
        HashSet usedNums = new HashSet();

        int numberIndex;
		String[] see = new String[count];
 		int i = 0;

	  while ((strLine = br.readLine()) != null)   {



			see[i] = strLine;

	              i = i + 1;
          }
                           for ( i=1; i <=200; i++) {
                           do{numberIndex = mixture.nextInt(see.length);
                           }

                           while(!usedNums.add(numberIndex) );


                     System.out.println(see[numberIndex]);
                          }


      ln.close();
       in.close();

 }
    catch (Exception e){
      System.err.println("Error: " + e.getMessage());
    }
  }
}

This loop loops infinitely.

do
{
  numberIndex = mixture.nextInt(see.length);
}

while(!usedNums.add(numberIndex) );

Check the javaDoc for HashSet and look to the add method.

Hope it helps.

This article has been dead for over six months. Start a new discussion instead.