Reverse Integer Array in Java

In this example, We will show simple example about, How to reverse integer array in java. The example has been tested and shared in the same post.

Reverse Integer Array in Java

Example Program

package com.dineshkrish;
/**
* 
* @author Dinesh Krishnan
* 
*/
public class ArrayReverse {
public static void main(String[] args) {
// Your Array
int[] array = { 10, 20, 30, 40, 50, 60 };
// getting the length of the array
int len = array.length;
// iterating the array
for (int i = 0; i < len / 2; i++) {
// swapping
int temp = array[i];
array[i] = array[len - 1 - i];
array[len - 1 - i] = temp;
}
// printing the result
for (int a : array) {
System.out.print(a + " ");
}
}
}

Output

—-

Your Input:
{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}

Your Output:
{100, 90, 80, 70, 60, 50, 40, 30, 20, 10}

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *