Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Main
- {
- public static void main(String args[])
- {
- Scanner src=new Scanner(System.in);
- System.out.println("Enter the size of array");
- int n=src.nextInt();
- int arr[]=new int[n];
- for(int i=0;i<n;i++)
- {
- System.out.println("Enter element");
- arr[i]=src.nextInt();
- }
- System.out.println("The entered array is");
- for(int j=0;j<n;j++)
- {
- System.out.println(arr[j]);
- }
- ArrayList<Integer> repeat =new ArrayList<>();
- for(int k=0;k<n;k++)
- {
- int rp=arr[k];
- for(int j=k+1;j<n;j++)
- {
- if (rp==arr[j])
- {
- repeat.add(arr[j]);
- }
- }
- }
- System.out.println("The duplicate elements in array are "+repeat);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement