Remove Duplicate Elements In Array And Count Repeated Occurrences In An Array.
package ArrayPrograms;
import java.util.Scanner;
public class prog4_big {
public static void main(String[] args)
{
Scanner scan =new Scanner(System.in);
System.out.println("Enter size for array :");
int size=scan.nextInt();
int[] a1=new int[size];
int[] a2=new int[size];
for (int i = 0; i < a1.length; i++) {
a1[i]=scan.nextInt();
}
int index=0;
for (int i = 0; i < a1.length; i++)
{
int count=0;
int val=a1[i];
for (int j = i; j < a1.length; j++)
{
if(val==a1[j])
{
count++;
}
if(count==1 && j==a1.length-1)
{
a2[index]=val;
index++;
}
}
}
for (int i = 0; i < a2.length; i++)
{
int a=a2[i];
int count=0;
for (int j = 0; j < a1.length; j++)
{
if(a==a1[j])
count++;
}
if(a!=0)
System.out.println(a+" number of occurances is "+count);
}
}
}
Comments
Post a Comment