Write a Java method only the method called Reverse Array tha

Write a Java method (only the method), called Reverse Array, that a single-dimensional array of Boolean values and returns a new array that contains the values in reverse order.

Solution

Hi, Please find my implementation.


public static boolean[] ReverseArray(boolean[] arr){
  
   // length of input array
   int length = arr.length;

   // creating a new array of size arr.length
   boolean[] reverse = new boolean[length];

   // traversing input array from back and storing in new array(reverse) from front
   int k=0;

   for(int i=length-1; i>=0; i--)
       reverse[k++] = arr[i];

   return reverse;

}

 Write a Java method (only the method), called Reverse Array, that a single-dimensional array of Boolean values and returns a new array that contains the values

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site