int[] numbers = {3, 2, 5, 11, 7, 10, 11, 3, 15, 11, 17, 10, 5};
int count = 0;
boolean dup = false;
System.out.println("arrays value");
for (int n : numbers ) {
System.out.print(n +" ");
}
System.out.println("\n\nDuplicated value on arrays: ");
for (int a = 0 ; a < numbers.length ; a++ ) {
for (int b = a + 1 ; b < numbers.length ; b++ ) {
if (numbers[a] == numbers[b]) {
count = numbers[a];
dup = true;
}
}
if (dup) {
System.out.print(count +" ");
dup = false;
count = 0;
}
}
I want to print duplicated value only once each using only for loop and if
this output will print 3 5 11 10 11, how do I make only 3 5 11 10.