FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/sorting_array.java at main · sksalahuddin2828/Java · GitHub
sksalahuddin2828
/
Java
Public
Notifications
You must be signed in to change notification settings
Fork
59
Star
178
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
sorting_array.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (31 loc) · 994 Bytes
Breadcrumbs
Java
/
sorting_array.java
Copy path
File metadata and controls
38 lines (31 loc) · 994 Bytes
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
31
32
33
34
35
36
37
38
import
java
.
util
.
Arrays
;
public
class
ArrayEquality
{
public
static
boolean
areArraysEqual
(
int
[]
array1
,
int
[]
array2
) {
int
length1
=
array1
.
length
;
int
length2
=
array2
.
length
;
// If lengths of arrays are not equal, they are not equal
if
(
length1
!=
length2
) {
return
false
;
}
// Sort both arrays
Arrays
.
sort
(
array1
);
Arrays
.
sort
(
array2
);
// Linearly compare elements
for
(
int
i
=
0
;
i
<
length1
;
i
++) {
if
(
array1
[
i
] !=
array2
[
i
]) {
return
false
;
}
}
// If all elements are the same
return
true
;
}
public
static
void
main
(
String
[]
args
) {
int
[]
array1
= {
3
,
5
,
2
,
5
,
2
};
int
[]
array2
= {
2
,
3
,
5
,
5
,
2
};
if
(
areArraysEqual
(
array1
,
array2
)) {
System
.
out
.
println
(
"The arrays are equal"
);
}
else
{
System
.
out
.
println
(
"The arrays are not equal"
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL