FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Essentials/ReversingArray.java at master · Sayantan7D/Java-Essentials · GitHub
Sayantan7D
/
Java-Essentials
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
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-Essentials
/
ReversingArray.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (31 loc) · 1.04 KB
Breadcrumbs
Java-Essentials
/
ReversingArray.java
Copy path
File metadata and controls
43 lines (31 loc) · 1.04 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
31
32
33
34
35
36
37
38
39
40
41
42
43
import
java
.
util
.
Arrays
;
import
java
.
util
.
Scanner
;
public
class
ReversingArray
{
private
static
Scanner
sc
=
new
Scanner
(
System
.
in
);
public
static
int
[]
getdata
(
int
capacity
){
int
[]
array
=
new
int
[
capacity
];
System
.
out
.
println
(
"
\n
Enter "
+
capacity
+
" elements -
\n
"
);
for
(
int
i
=
0
;
i
<
capacity
;
i
++){
array
[
i
]=
sc
.
nextInt
();
}
return
array
;
}
public
static
void
reverse
(
int
[]
arr
){
int
maxindex
=(
arr
.
length
)-
1
;
int
halfway
=(
arr
.
length
)/
2
;
for
(
int
i
=
0
;
i
<
halfway
;
i
++){
int
temp
=
arr
[
i
];
arr
[
i
]=
arr
[
maxindex
-
i
];
arr
[
maxindex
-
i
]=
temp
;
}
}
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
(
"
\n
Enter the total number of elements in the array - "
);
int
n
=
sc
.
nextInt
();
int
[]
arr
=
new
int
[
n
];
arr
=
getdata
(
n
);
System
.
out
.
println
(
"
\n
Input Array - "
+
Arrays
.
toString
(
arr
));
reverse
(
arr
);
System
.
out
.
println
(
"
\n
Reversed Array - "
+
Arrays
.
toString
(
arr
));
}
}
Back
|
FazBrowse Home
|
New Git URL