# Posted By

indecs on 08/21/15

# Statistics

Viewed 482 times
Favorited by 1 user(s)

# 3 ways to reverse array in Java

/ Published in: Java
`import java.util.Arrays;public class Practive{	public static void main (String[] args)	{		int [] array = new int[] {23,45,34,54,67,78};		System.out.println("Original array:");		System.out.println(Arrays.toString(array));		//reverse method 1:		int i =0;		while ( i< (array.length)/2){					for (int j = array.length-1; j>i;j--){				int tempf = array[i];				int tempb = array[j];				array[i] = tempb;				array[j]= tempf;				i++;				System.out.println("Reverse array");				System.out.println(Arrays.toString(array));				}  		}   	} }  /*	//reverse method 2:import java.util.Arrays;public class Practive{public static void main (String[] args){	int [] array = new int[] {23,45,34,54,67,78};	System.out.println("Original array:");	System.out.println(Arrays.toString(array));	//reverse	for (int i =0; i< (array.length)/2; i++){				for (int j = array.length-1; j>i;j--){			int tempf = array[i];			int tempb = array[j];			array[i] = tempb;			array[j]= tempf;			i++;			System.out.println("Reverse array");			System.out.println(Arrays.toString(array));			}  	} } } */  /* import java.util.Arrays;public class Practive{public static void main (String[] args){	int [] array = new int[] {23,45,34,54,67,78};	System.out.println("Original array:");	System.out.println(Arrays.toString(array));	//reverse method 3	for (int i =0; i< (array.length)/2; i++){			int temp = array[i];		array[i] = array[array.length -1 -i];		array[array.length-1-i]= temp;		System.out.println("Reverse array");		System.out.println(Arrays.toString(array));			}  	} }*/`