Answers for "Reversing an array"

C++
21

reversing an array in js

var arr=[1,2,5,6,2]
arr.reverse()
Posted by: Guest on June-26-2020
12

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
5

how to reverse an array in javascript

array = [1 2, 3]
reversed = array.reverse()
Posted by: Guest on January-21-2021
2

reverse string array java

//java program to reverse array using for loop
public class ReverseArrayDemo 
{
   public static void main(String[] args) 
   {
      int[] arrNumbers = new int[]{2, 4, 6, 8, 10};  
      System.out.println("Given array: ");  
      for(int a = 0; a < arrNumbers.length; a++)
      {
         System.out.print(arrNumbers[a] + " ");
      }
      System.out.println("Reverse array: ");
      // looping array in reverse order
      for(int a = arrNumbers.length - 1; a >= 0; a--) 
      {  
         System.out.print(arrNumbers[a] + " ");  
      }
   }
}
Posted by: Guest on November-07-2020
2

reverse string array java

import java.util.Arrays;
public class ReverseStringArrayInJava
{
   public static void main(String[] args)
   {
      String[] strHierarchy = new String[]{"Junior Developer","Senior Developer","Team Lead","Project Manager","Senior Manager","CEO"};
      System.out.println("Given string array: " + Arrays.toString(strHierarchy));
      for(int a = 0; a < strHierarchy.length / 2; a++)
      {
         String strTemp = strHierarchy[a];
         strHierarchy[a] = strHierarchy[strHierarchy.length - a - 1];
         strHierarchy[strHierarchy.length - a - 1] = strTemp;
      }
      System.out.println("Reversed string array: ");
      for(int a = 0; a < strHierarchy.length; a++)
      {
         System.out.println(strHierarchy[a]);
      }
   }
}
Posted by: Guest on November-07-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

Browse Popular Code Answers by Language