Advertisement
d1i2p3a4k5

2.duplicate array

Oct 18th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. class duplicate
  4. {
  5.     public static void main(String args[])
  6.     {
  7.         Scanner t = new Scanner(System.in);
  8.         System.out.println("Enter the size of array");
  9.         int n = t.nextInt();
  10.         int i,k,j;
  11.         int a[] = new int[n];
  12.         System.out.println("enter elements in array");
  13.         for(i=0;i<n;i++)
  14.         {
  15.         a[i] = t.nextInt();
  16.         }
  17.         System.out.println("original array is given below:");
  18.         for(i=0;i<n;i++)
  19.         {
  20.         System.out.print(a[i]+"   ");
  21.         }
  22.         System.out.println("");
  23.         for(i=0;i<n;i++)
  24.         {
  25.             for(j=i+1;j<n;)
  26.             {
  27.                 if(a[i]==a[j])
  28.                 {
  29.                     for(k=j;k<n-1;k++)
  30.                     {
  31.                         a[k]=a[k+1];
  32.                        
  33.                     }
  34.                                    n--;
  35.                 }
  36.                 else
  37.                 j++;
  38.             }
  39.         }
  40.         System.out.println("updated array is given below:");
  41.         for(i=0;i<n;i++)
  42.         {
  43.             System.out.print(a[i]+" ");
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement