Qn: Write a java program to remove the duplicates in an array?
-By Admin, Last Update On 22nd May,2019 11:46 pm
Program
import java.util.Scanner;
public class RemoveDuplicate{
public static void main(String args[]){
int count = 0, i, j;
int a[]={2,8,3,6,3,5,7,2,6,9,2,8};
int b[]=new int[a.length];
for (i=0;i<a.length;i++){
for (j=0;j<count;j++){
if(a[i] == b[j]){
break;
}
}
if (j==count){
b[count]=a[i];
count++;
}
}
System.out.println("Array after removing duplicate elements:");
for (i=0;i<count;i++){
System.out.print(b[i]+", ");
}
}
}
Output:
Array after removing duplicate elements:
2
8
3
6
5
7
9
Array after removing duplicate elements:
2
8
3
6
5
7
9
Pgcomments
இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.
Comments