Sunday, 24 January 2021

frequency of an element in an array


import java.io.*;
class freq
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the number of digits");
        int n=Integer.parseInt(br.readLine());
        int f=0;
        System.out.println("entre the numbers");
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=Integer.parseInt(br.readLine());
        }
        for(int i=0;i<n;i++)
        {
            int c=0;
            int c1=0;
            f=a[i];
            for(int j=i-1;j>=0;j--)
            {
               if(a[i]==a[j])
               {
                   c=c+1;
                }
            }
            if(c==0)
            {
                for(int j=i;j<n;j++)
                {
                    if(a[i]==a[j])
                    {
                        c1=c1+1;
                    }
                }
                System.out.println("frequency of"+a[i]+"is ="+c1);
            }
        }
    }
}

No comments:

Post a Comment

HAY THAKYOU FOE VISIT

Program(python):-Find duplicates in an array (Geeks for geek problem)

QUESTION:- Given an array  a  of size  N  which contains elements from  0  to  N-1 , you need to find all the elements occurring more than o...