Latest :

Java Program To Reverse An Array | Programs

Java program to reverse an array – We will discuss the various methods to reverse an array in Java. The compiler has been added so that you can execute the programs by yourself, alongside few suitable examples and sample outputs. The reverse an array Java program has been written in Two different ways here.

  • Without Using Another Array
  • Using Class

Standard Array Reversal


Without Using Another Array

1) Insert the elements in to the array “array[]” using scanner class method s.nextInt().

2) To reverse the array we are interchanging the n-1 element with the i’th element by increasing i value and decreasing the n value until i<n.


Using Class

1) The class “Reverse” will reverse the given array.

2) Reverse res=new Reverse(array,n), creating the Reverse class object res by passing the array, number of elements in the array. Then Reverse class constructor Reverse(int[] a,int n) will be executed.

  • for i=length of the array to i>0 and  j=0 to j<length of the array
  • rev[j] = a[i-1]


More Java Programs Here:


Check Also

Merge Sort Java – Program 2 Ways | Sortings

Merge Sort Java –  Java program to implement merge sort using array & Buffered reader. ...