-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseArray.java
More file actions
28 lines (22 loc) · 927 Bytes
/
Copy pathReverseArray.java
File metadata and controls
28 lines (22 loc) · 927 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
//Reverse Array element
import java.util.Scanner;
public class ReverseArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Size Of Array");
int size = sc.nextInt();
int array[] = new int[size];
System.out.println("Enter Array Element:");
for (int index = 0; index < array.length; index++) {
array[index] = sc.nextInt();
}
System.out.println("Reverse Array is : ");
for (int index = array.length - 1; index >= 0; index--) { // i must be array.length-1 because Exception in
// thread
// "main"
// java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds
// for length 3
System.out.println(array[index]);
}
}
}