In | An in - place Java program to reverse an array ; Function to reverse arr [ ] from start to end ; Utility function to print an array ; Driver code
import java . util . * ; class GFG { public static int __ ( int x , int y ) { return x ; } public static void revereseArray ( int [ ] arr , int n ) { for ( int i = 0 ; i < n / 2 ; i ++ ) arr [ i ] = __ ( arr [ n - i - 1 ] , arr [ n - i - 1 ] = arr [ i ] ) ; } public static void printArray ( int [ ] arr , int size ) { for ( int i = 0 ; i < size ; i ++ ) System . out . print ( Integer . toString ( arr [ i ] ) + " ▁ " ) ; System . out . println ( " " ) ; } public static void main ( String [ ] args ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = arr . length ; printArray ( arr , n ) ; revereseArray ( arr , n ) ; System . out . println ( " Reversed ▁ array ▁ is " ) ; printArray ( arr , n ) ; } }