-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountOccurence
More file actions
39 lines (30 loc) · 875 Bytes
/
Copy pathCountOccurence
File metadata and controls
39 lines (30 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package arrayImpl;
import java.util.Scanner;
public class CountOccurence {
private static Scanner sc;
public static void main(String[] args) {
int i,x,n,count=0;
sc = new Scanner(System.in);
System.out.println("Enter the no of Elements to enter: ");
n=sc.nextInt();
int arr[]= new int[n];
System.out.println("Enter all the Elements:");
for(i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
System.out.print("Enter the element of which you want to count number of occurrences:");
x = sc.nextInt();
for(i = 0; i < n; i++)
{
if(arr[i] == x)
{
count++;
}
}
if(count==0)
System.out.println("Number not found");
else
System.out.println("Number of Occurrence of the Element:"+count);
}
}