mercredi 28 novembre 2018

Change value in boolean array. Choose place not value

I,m not sure this is possible. I,m building a program to choose a lotto row. I have a for loop to random pick seven numbers from 1 to 35. My plan is that i can make a boolean array and then take one of the random numbers to choose a place (not a value) in the boolean array and change it to True.

In this way i have the row number and i,m sure that the number is taken when the array place i true.

import java.util.Random; {


public static void main(String[] args) {
    int randomNr;
    boolean[] lottoRow = new boolean[35];

    Random randNr = new Random();

    for(int i=0; i<7; i++) {
        randomNr = randNr.nextInt(35)+1;

    }
}

How would i do this? Is it even a good way to approach this problem?




Aucun commentaire:

Enregistrer un commentaire