1

I ran into this problem:

I want to check if the row contains duplicate values and only return it if it does, otherwise redo the generation (the if statement).

It seems like thats the simplest way to do this, but if you have any other idea please share.

I got this code in a class:

public int[] createRow(){
    NumberGenerator c = new NumberGenerator();    

    int row [] = new int [7];
    for (int i = 0; i < row.length; i++) {       
        row[i] = c.randomizeNumber(i);
    }
    return row;
}     

1 Answers1

1

Can you try HashSet<Integer> instead of array.

public HashSet<Integer> createRow(){
   NumberGenerator c = new NumberGenerator();    

   Set<Integer> arr = new HashSet<Integer>(); 
   for (int i = 0; i < 7; i++) {
    arr.add(c.randomizeNumber(i));

   }
   return arr;
} 
matt
  • 10,892
  • 3
  • 22
  • 34