I am creating a code to develop my studies in Java and gave me an interesting idea / challenge:
One person has 5 cards from MegaSena and always plays with the same cards. I made a small code where you enter the numbers of the last draw and he checks to see if he hits the cards. See:
public static void main(String[] args) {
int[] cartela1 = {13,25,32,47,59,60};
int[] cartela2 = {14,26,33,48,55,60};
int[] cartela3 = {18,63,41,25,21,36};
int[] cartela4 = {14,26,33,48,55,60};
int[] cartela5 = {13,25,32,47,59,60};
int[] numSorteio = new int[6];
int i,j;
int count = 0;
Scanner scan = new Scanner(System.in);
for (i=0; i<numSorteio.length; i++) {
System.out.println("Digite o número sorteado na posição: " +i);
numSorteio[i] = scan.nextInt();
}
for (i=0; i<6; i++) {
for (j=0; j<6; j++) {
if (numSorteio[j] == cartela1[i]) {
System.out.println("Seu número " + cartela1[i]+ " foi sorteado!");
count++;
}
}
}
System.out.println("Você acertou " +count+ " números na cartela 1!");
}
As you can see my code works perfectly showing on the output the numbers I hit and the quantity.
But I only managed to do it for cartela1, if I repeated FOR 5 times it would be perfect for 5 cards, but I wanted to do it in a shorter and more elegant way.