Answer :

ijeggs

Answer:

public class Reverse {

  1.    public static void reverseList(int list [], int n)
  2.    {
  3.        int[] reversedList = new int[n];
  4.        int k = n;
  5.        for (int i = 0; i < n; i++) {
  6.            reversedList[k - 1] = list[i];
  7.            k = k - 1;
  8.        }
  9.        //printing the reversed list
  10.        System.out.println("The Reversed list \n");
  11.        for (int j = 0; j < n; j++) {
  12.            System.out.println(reversedList[j]);
  13.        }
  14.    }

Explanation:

Using Java, An array is implemented to hold a list of items

A method reverseList() is created to accept an array as parameter and using a for statement reverses the elements of the array and prints each element of the list

See below a complete code with a main method that calls this method

public class Reverse {

   public static void main(String[] args) {

       int [] arr = {10, 20, 30, 40, 50};

       reverseList(arr, arr.length);

   }

   public static void reverseList(int list [], int n)

   {

       int[] reversedList = new int[n];

       int k = n;

       for (int i = 0; i < n; i++) {

           reversedList[k - 1] = list[i];

           k = k - 1;

       }

       //printing the reversed list

       System.out.println("The Reversed list \n");

       for (int j = 0; j < n; j++) {

           System.out.println(reversedList[j]);

       }

   }

}

Other Questions