FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javaprogram/Frequency.java at master · seeditsolution/javaprogram · GitHub
seeditsolution
javaprogram
Repository navigation
Code
Issues
5
(5)
Pull requests
296
(296)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
javaprogram
/
Frequency.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (29 loc) · 1.2 KB
Breadcrumbs
javaprogram
/
Frequency.java
Copy path
File metadata and controls
30 lines (29 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
public
class
Frequency
{
public
static
void
main
(
String
[]
args
) {
//Initialize array
int
[]
arr
=
new
int
[] {
1
,
2
,
8
,
3
,
2
,
2
,
2
,
5
,
1
};
//Array fr will store frequencies of element
int
[]
fr
=
new
int
[
arr
.
length
];
int
visited
= -
1
;
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++){
int
count
=
1
;
for
(
int
j
=
i
+
1
;
j
<
arr
.
length
;
j
++){
if
(
arr
[
i
] ==
arr
[
j
]){
count
++;
//To avoid counting same element again
fr
[
j
] =
visited
;
}
}
if
(
fr
[
i
] !=
visited
)
fr
[
i
] =
count
;
}
//Displays the frequency of each element present in array
System
.
out
.
println
(
"---------------------------------------"
);
System
.
out
.
println
(
" Element | Frequency"
);
System
.
out
.
println
(
"---------------------------------------"
);
for
(
int
i
=
0
;
i
<
fr
.
length
;
i
++){
if
(
fr
[
i
] !=
visited
)
System
.
out
.
println
(
" "
+
arr
[
i
] +
" | "
+
fr
[
i
]);
}
System
.
out
.
println
(
"----------------------------------------"
);
}}
Back
|
FazBrowse Home
|
New Git URL