-
Notifications
You must be signed in to change notification settings - Fork 0
/
Freq.java
46 lines (36 loc) · 1.09 KB
/
Freq.java
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
40
41
42
43
44
45
46
import java.util.Scanner;
public class Freq {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the array size");
int n = sc.nextInt();
int nums[] = new int[n];
boolean visited[] = new boolean[n];
int freq[] = new int[n];
System.out.println("Enter the array elements");
for(int i=0; i<n; i++)
{
nums[i]=sc.nextInt();
visited[i]=false;
freq[i]=1;
}
for(int i=0; i<nums.length-1; i++)
{
for(int j=i+1; j<nums.length; j++)
{
if(nums[i]==nums[j] && visited[j]!=true)
{
freq[i]++;
visited[j]=true;
}
}
}
for(int i=0; i<nums.length; i++)
{
if(visited[i]==false)
{
System.out.println(nums[i]+":"+ freq[i]);
}
}
}
}