-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberOccurrenceCounter.java
More file actions
34 lines (33 loc) · 1.07 KB
/
Copy pathNumberOccurrenceCounter.java
File metadata and controls
34 lines (33 loc) · 1.07 KB
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
import java.io.*;
public class NumberOccurrenceCounter {
public static void main() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER THE RANGE=");
int n = Integer.parseInt(br.readLine());
int arr[] = new int[n];
System.out.println("ENTER THE NUMBERS=");
int occ = 0, count = 0;
int f[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i] == arr[j])
occ++;
}
f[count++] = occ;
occ = 0;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] == arr[j])
arr[i] = 0;
}
}
for (int i = 0; i < n; i++) {
if (arr[i] != 0)
System.out.println(arr[i] + " APPEARS FOR " + f[i] + " TIMES");
}
}
}