Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- class duplicate
- {
- public static void main(String args[])
- {
- Scanner t = new Scanner(System.in);
- System.out.println("Enter the size of array");
- int n = t.nextInt();
- int i,k,j;
- int a[] = new int[n];
- System.out.println("enter elements in array");
- for(i=0;i<n;i++)
- {
- a[i] = t.nextInt();
- }
- System.out.println("original array is given below:");
- for(i=0;i<n;i++)
- {
- System.out.print(a[i]+" ");
- }
- System.out.println("");
- for(i=0;i<n;i++)
- {
- for(j=i+1;j<n;)
- {
- if(a[i]==a[j])
- {
- for(k=j;k<n-1;k++)
- {
- a[k]=a[k+1];
- }
- n--;
- }
- else
- j++;
- }
- }
- System.out.println("updated array is given below:");
- for(i=0;i<n;i++)
- {
- System.out.print(a[i]+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement