/*Removes All The Duplicte Elements From The Array*/
import java.io.*;
class Duplicate
{
int num[],y;
void readlist()throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
num=new int[10];
for(int i=0;i<10;i++)
{
System.out.println("Enter a number");
num[i]=Integer.parseInt(x.readLine());
}
}
void packlist()
{
int s=num[0],l=num[0],c=0;
int dup[]=new int [10],k=0;
y=0;
for(int i=0;i<10;i++)
{
if(s>num[i])
s=num[i];
if(l<num[i])
l=num[i];
}
for(int i=s;i<=l;i++)
{
c=0;
for(int j=0;j<10;j++)
{
if(i==num[j]&&c==0)
{
dup[k]=i;
c=1;y++;k++;
}
}
}
System.out.println("After removing duplicate elements, new list is ");
displaylist(dup);
}
void displaylist(int a[])
{
for(int i=0;i<y;i++)
{
System.out.print(a[i]+" ");
}
}
}
import java.io.*;
class Duplicate
{
int num[],y;
void readlist()throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
num=new int[10];
for(int i=0;i<10;i++)
{
System.out.println("Enter a number");
num[i]=Integer.parseInt(x.readLine());
}
}
void packlist()
{
int s=num[0],l=num[0],c=0;
int dup[]=new int [10],k=0;
y=0;
for(int i=0;i<10;i++)
{
if(s>num[i])
s=num[i];
if(l<num[i])
l=num[i];
}
for(int i=s;i<=l;i++)
{
c=0;
for(int j=0;j<10;j++)
{
if(i==num[j]&&c==0)
{
dup[k]=i;
c=1;y++;k++;
}
}
}
System.out.println("After removing duplicate elements, new list is ");
displaylist(dup);
}
void displaylist(int a[])
{
for(int i=0;i<y;i++)
{
System.out.print(a[i]+" ");
}
}
}
No comments:
Post a Comment