Java Program to reverse elements of an array

Java Program to reverse elements of an array.

import java.util.*;
public class onedimensionalarray6
{
public static void main(String[]args)
{
  int n=8;
  int a[]={1,2,6,8,9,7,5,3};
  for(int i=0,j=n/2;i<n/2;i++,j++)
  {
    int t=a[i];
    a[i]=a[j];
    a[j]=t;
}
  for(int i=0;i<n;i++)
    System.out.println(a[i]);
}
}

Leave a Reply

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