Showing posts with label only. Show all posts
Showing posts with label only. Show all posts

Friday, February 10, 2012

Java program To remove duplicates from an array of integers so that each number may appear only once

import java.io.*;
class remDup
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the length of the array: ");
int l=Integer.parseInt(br.readLine());
int[]a=new int[l];
for(int i=0; i {
System.out.print("Enter the element number "+(i+1)+" of the array: ");
a[i]=Integer.parseInt(br.readLine());
}

//now the real work begins

for(int i=0; i {
for(int j=i+1; j {
while(a[i]==a[j])
{
for(int A=j; A a[A]=a[A+1];
l--;
}
}
}

// real work is done now!!!!


for(int i=0; i {
System.out.println(a[i]);
}

}// end of main
}// end of class