reverse an array without using another array in java

Solutions on MaxInterview for reverse an array without using another array in java by the best coders in the world

showing results for - "reverse an array without using another array in java"
Bennett
07 Mar 2018
1// Reverse an array without using another array in java
2import java.util.Scanner;
3public class ReverseWithoutArray 
4{
5      public static void main(String[] args) 
6      {
7         int number, temp, a;
8         Scanner sc = new Scanner(System.in);
9         System.out.print("Please enter number of elements in the array: ");
10         number = sc.nextInt();
11         int[] arrayNumbers = new int[number];
12         System.out.println("Please enter " + number + " number elements.");
13         for(a = 0; a < number; a++)
14         {
15             arrayNumbers[a] = sc.nextInt();
16         }
17         for(a = 0; a < number; a++, number--)
18         {
19             temp = arrayNumbers[a];
20             arrayNumbers[a] = arrayNumbers[number - 1];
21             arrayNumbers[number - 1] = temp;
22         }
23         System.out.println("Reverse of an array is : ");
24         for(a = 0; a < arrayNumbers.length; a++)
25         {
26             System.out.println(arrayNumbers[a]);
27         }
28         sc.close();
29      }
30}