3
I want to store random numbers from 1 to 60 in an array. When there are equal numbers on the lines, it is to generate another random number.
Type, cannot be: 11 55 55 43 49 30, and yes should be 11 55 52 43 49 30. There should be no repetitions.
I made this code that generates normally, but I wanted to remove the repeated numbers from the lines and put new numbers that are not equal.
package Tentativa;
import java.util.Random;
public class Loteria {
    public static void main(String[] args) {
        int[][]mega = new int[7][6];
        int[][]numero = new int[7][6];
        Random gerador = new Random();
        for(int x=0; x<7; x++) {
            for(int y=0; y<6; y++) {
                mega[x][y] = gerador.nextInt(60) + 1;
            }   
        }
        for(int x=0; x<7; x++) {
            for(int y=0; y<6; y++) {
                System.out.print(mega[x][y] + " ");
            }
            System.out.println();
        }
    }
}
Just add a detail: it is using array.. so after generating the list you need to do one
lista.toArray()– Pedro Laini
@Pedrolaini is true, but I don’t know if he needs it and should use the array.
– Maniero
It is. And I was seeing here: the
lista.toArray()returns aObject[ ]and not to convert toint[ ]... then you have to iterate in the list and insert elements 1 to 1 in the array– Pedro Laini
@Pedrolaini anyway he wants the other way.
– Maniero