// Repetaded element run multiple times means avoid duplicate element count multiple times
import java.util.Scanner;
public class FindFrequency {
public static void main(String[] args) {
int t, count=0;
Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements to insert in an array: ");
int len = in.nextInt();
int[] arr = new int[len];
System.out.println("Enter elements to insert in an array: ");
for( int i=0;i<len;i++)
{
t = in.nextInt();
arr[i] = t;
}
System.out.println("\n");
for(int i=0;i<len;i++)
{
count=1;
for(int j=i+1;j<=len-1;j++)
{
if(arr[i]==arr[j] )
{
count++;
}
}
System.out.println(arr[i] + " is " + count + " times.\n");
}
}
}
Aucun commentaire:
Enregistrer un commentaire