lundi 12 avril 2021

Finding repeating numbers within a column in a 2D array

I'm making a digital Bingo board using numbers and I want all the numbers to be unique. So I'm trying to create an algorithm that will loop through the column, find repeating numbers and then replace them with a random number between two certain numbers.

This is what I have so far:

    public void bingoBoardGenrerator(int[][] bingoBoard)
   {    
     for (int row = 0; row < bingoBoard.length; row++)
     {
      int random = (int)(Math.random()*15)+ 1;
      bingoBoard[row][0] = random; 
       for (int j = 1; j <bingoBoard.length; j++)
        {
         if (bingoBoard[j][0] == random)
         {
           bingoBoard[row][0] = (int)(Math.random()*15 ) + 1;
          }
        }

The output should look like this but without the repeating numbers in the columns:

 Free space = 0

B   I   N   G   O   

5   25  36  53  61  
9   19  36  60  62  
1   17  0   54  63  
6   20  37  57  71  
5   19  39  57  69  

Any help would be really appreciated!




Aucun commentaire:

Enregistrer un commentaire