-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathReverseArray.java
More file actions
44 lines (29 loc) · 849 Bytes
/
ReverseArray.java
File metadata and controls
44 lines (29 loc) · 849 Bytes
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
/**
* Created by root on 8/3/17.
*/
package EPC;
import java.util.Scanner;
public class ReverseArray
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of elements you wish to enter");
int n = in.nextInt();
int store;
int [] array = new int[n];
System.out.println("enter your integers");
for (int i = 0; i <n ; i++) {
array[i] = in.nextInt();
}
for (int i = 0; i <n/2 ; i++) {
store = array[i];
array[i] = array[(n-1)-i];
array[(n-1)-i] = store;
}
System.out.println("Your reversed array is:");
for (int i = 0; i <n ; i++) {
System.out.print(" "+ array[i]);
}
System.out.println();
}
}