package com.altafjava.fdeia.test;
public class Test {
public static void main(String[] args) {
int[] arr={1,6,5,1,2,2,9,6};
System.out.println("Input Array = 1,6,5,1,2,2,9,6");
System.out.print("The repeating elements are : ");
for (int i = 0; i < arr.length; i++)
{
for(int j=i+1;j<arr.length;j++){
if(arr[i]==arr[j]){
System.out.print(arr[i]+" ");
break;
}
}
}
}
}
Note:-
We are using Brute Force Mechanism. This will take lot of time. Hence we can take the help of HashSet but in interview they check your logical skill.
We are using Brute Force Mechanism. This will take lot of time. Hence we can take the help of HashSet but in interview they check your logical skill.
How to find duplicate elements in an array? |
0 Comment to "How to find duplicate elements in an array?"
Post a Comment