Answers for "how to reverse the order of an array"

13

reverse array in java

int length = array.length;
		for(int i=0;i<length/2;i++) {
			int swap = array[i];
			array[i] = array[length-i-1];
			array[length-i-1] = swap;
		}
or
Collections.reverse(Arrays.asList(array));
Posted by: Guest on May-10-2020
-1

Reversing an array

#include<iostream>
using namespace std;
int main()
{
	int Arr[100],n,temp,i,j;
	cout<<"Enter number of elements you want to insert ";
	cin>>n;
	for(i=0;i<n;i++)
	{
		cout<<"Enter element "<<i+1<<":";
		cin>>Arr[i];
	}
	for(i=0,j=n-1;i<n/2;i++,j--)
	{
		temp=Arr[i];
		Arr[i]=Arr[j];
		Arr[j]=temp;
	}
	cout<<"\nReverse array"<<endl;
	for(i=0;i<n;i++)
		cout<<Arr[i]<<" ";
	return 0;
}
Posted by: Guest on May-11-2021

Code answers related to "how to reverse the order of an array"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language