Share this post on:

Here is an Example in Java to find the number of occurrence from an Array.

public class Demo {
public static void main(String[] args) {

    int count=0;
    Scanner in= new Scanner(System.in);
    System.out.println("Enter the range of array");
    int n= in.nextInt();
    int a[] = new int[n];
    System.out.println("Enter the element");
    for(int i=0;i<n;i++)
    {
        a[i] = in.nextInt();
    }
    System.out.println("Enter the element to find");
    int x = in.nextInt();
    for(int i=0;i<n;i++)
    {
        if(a[i]==x)
        {
            count++;
        }
    }
    System.out.println("No of occurence is "+count);
}}
Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

Leave a Comment

Your email address will not be published. Required fields are marked *