How to find the duplicate values of an array of integers in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int[] array = {8, 3, 1, 3, 6, 5, 5, 1, 9, 0};
  
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if ((array[i] == array[j]) && (i != j)) {
                    System.out.println(array[j]);
                    break;
                }
            }
        }
    }
}
 
 
 
  
/*
run:
  
3
1
5
  
*/

 



answered Aug 19, 2021 by avibootz
edited Aug 20, 2021 by avibootz
...