Pessoal. Estou escrevendo um exercício para a faculdade, mas depois de escrever o código todo, o resultado da minha interação com as arrays não esta funcionando. Alguém poderia me ajudar em achar o erro na logica do meu código?
import static java.lang.System.out;
class Task4 {
public static void main(String[] args) {
// Array declaration
int[] arr = {2, 3, 4, 3, 6, 7, 6, 8, 2, 9};
int[] brr = {2, 3, 6, 8, 5, 1};
// Presentation print
out.println("int[] arr = {2,3,4,3,6,7,6,8,2,9};\nint[] brr = {2,3,6,8,5,1};");
out.print("Result = ");
// Variables declaration
int arrLen = arr.length;
int brrLen = brr.length;
int counter = 0;
// Iterate through every array
for (int index = 0; index < arrLen; index++) {
for (int index2 = 0; index2 < brrLen; index2++) {
if (arr[index] == brr[index2]) {
// Reset variable
counter = 0;
// Check in the first array if we still have duplicates
for (int index3 = index + 1; index3 < arrLen; index3++)
if (arr[index] == arr[index3])
counter++;
// Check in the second arry if we still have duplicates
for (int index4 = index2 + 1; index4 < brrLen; index4++)
if (arr[index] == brr[index4])
counter++;
// If we don't have a duplicate, print out results
if (counter == 2)
out.print(arr[index]);
}
}
}
}
}
Desde já agradeço a todos!