0

public class BingoWood {

public static void main(String[] args) {

bingoCard();

}

public static void bingoCard(){

    Random ran = new Random();

    System.out.println("B  I  N  G  O");

    int[][] board = new int [5][5];     

    for(int i = 0; i < board.length; i++){

        for(int j = 0; j < board.length; j++){

            board[0][j] = ran.nextInt(15) + 1;
            board[1][j] = ran.nextInt(15) + 16;
            board[2][j] = ran.nextInt(15) + 31;
            board[2][2] = 0;
            board[3][j] = ran.nextInt(15) + 46;
            board[4][j] = ran.nextInt(15) + 61;
            System.out.printf("%-3s",board[j][i]);   
        }
        System.out.println();
    }  

}

} enter image description here I am creating a bingo card using the above method, but I am having trouble getting the columns to have no repeating numbers. Is it the way I have coded the multidimensional array too broad for logic? Or does a way exist where I can keep the same chunk of code for the array and apply logic to exclude repeated numbers? New to coding / Java, any help is appreciated.

  • Do it in while, pushing new values to list, and checking if it's in list already – deathangel908 Jun 16 '18 at 21:48
  • Create multiple ArrayList containing the valid values for each column. Then you can use the Collections.shuffle(...) method to shuffle each ArrayList. Then you just remove the first entry from each list and assign it to the appropriate cell. – camickr Jun 16 '18 at 21:50
  • 1
    @ErnestKiwele, `You're anyway filling 25 arrays with 15 numbers...` - there are 75 numbers. Depending on the columns a different value is added to the random number. – camickr Jun 16 '18 at 21:54

0 Answers0