Skip to content

Instantly share code, notes, and snippets.

@thmain
Created June 18, 2017 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/9c7a5b6730e37a22ad9f38e34dffc88c to your computer and use it in GitHub Desktop.
Save thmain/9c7a5b6730e37a22ad9f38e34dffc88c to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class CheckDuplicatesUsingTwoLoops {
public void hasDuplicates2ForLoops(int [] arrA) {
for (int i = 0; i < arrA.length; i++) {
for (int j = i+1; j < arrA.length; j++) {
if(arrA[i]==arrA[j]){
System.out.println("Array has duplicates : " + arrA[i]);
}
}
}
}
public static void main(String[] args) {
int a [] = {1, 6, 5, 2, 3, 3, 2};
new CheckDuplicatesUsingTwoLoops().hasDuplicates2ForLoops(a);
}
}
@arjun26122002
Copy link

public class array {
public static void main(String[] args) {

    int[] arr = new int[] { 1, 2, 3, 4, 2, 7, 8, 8, 3 };

    System.out.println("Duplicate elements in given array: ");
    for (int i = 0; i < arr.length; i++) {
        for (int j = i + 1; j < arr.length; j++) {
            if (arr[i] == arr[j])
                System.out.println(arr[j]);
        }
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment