1int length = array.length;
2 for(int i=0;i<length/2;i++) {
3 int swap = array[i];
4 array[i] = array[length-i-1];
5 array[length-i-1] = swap;
6 }
7or
8Collections.reverse(Arrays.asList(array));
1import java.util.Scanner;
2public class Example
3{
4 public static void main(String args[])
5 {
6 int counter, i=0, j=0, temp;
7 int number[] = new int[100];
8 Scanner scanner = new Scanner(System.in);
9 System.out.print("How many elements you want to enter: ");
10 counter = scanner.nextInt();
11
12 /* This loop stores all the elements that we enter in an
13 * the array number. First element is at number[0], second at
14 * number[1] and so on
15 */
16 for(i=0; i<counter; i++)
17 {
18 System.out.print("Enter Array Element"+(i+1)+": ");
19 number[i] = scanner.nextInt();
20 }
21
22 /* Here we are writing the logic to swap first element with
23 * last element, second last element with second element and
24 * so on. On the first iteration of while loop i is the index
25 * of first element and j is the index of last. On the second
26 * iteration i is the index of second and j is the index of
27 * second last.
28 */
29 j = i - 1;
30 i = 0;
31 scanner.close();
32 while(i<j)
33 {
34 temp = number[i];
35 number[i] = number[j];
36 number[j] = temp;
37 i++;
38 j--;
39 }
40
41 System.out.print("Reversed array: ");
42 for(i=0; i<counter; i++)
43 {
44 System.out.print(number[i]+ " ");
45 }
46 }
47}