3
Unfortunately I’m not managing to generate more than a set of 6 numbers. The correct one would be to generate the amount of games that the user would type and would be stored in the variable jogos
.
import java.util.Random;
import java.util.Scanner;
/**
* AtividadeMegaSena
*/
public class AtividadeMegaSena {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
System.out.println("Quantos jogos você quer fazer?");
int jogos = teclado.nextInt();
Random aleatorio = new Random();
int[] numeros = new int[6];
for (int i = 1; i <= numeros.length; i++) {
System.out.println(aleatorio.nextInt(61));
}
teclado.close();
}
}
What’s that 61 there?
– Maniero
it was supposed to be (60)+ 1 not to bug, is pq a mega sena the numbers that can be chosen ranging from 1 to 60
– Breno Nogueira
You can use an array whose first dimension is the number of games and the second the size of each game (6). E.g.,:
int[][] jogosGerados = new int[jogos][6];
. Wrap your bow with another outer loop iterating between 0 andjogos
(e.g., with an indexj
). After generating the numbers assign each game to an input in the matrix, e.g.,jogosGerados[j] = numeros;
.– Anthony Accioly