Ask Question
20 July, 15:12

Write the definition of a method reverse, whose parameter is an array of integers. The method reverses the elements of the array. The method does not return a value.

If you pass an array of integers arr1 containing the values 2, 4, 6, 8, 10 to reverse, and print out the array after that, the output will be

10, 8, 6, 4, 2

+1
Answers (1)
  1. 20 July, 16:22
    0
    Following are the code in the Java Programming Language.

    //declare a function

    public void reverse (int arr1[]) {

    int x; / /set integer type variable

    //set integer type variable which stores array length

    int num = arr1. length;

    //set for loop for reversing an array

    for (int j = 0; j < arr1. length / 2; j++) {

    x = arr1[j];

    arr1[j] = arr1[num - j - 1];

    arr1[num - j - 1] = x;

    }

    }

    Explanation:

    Here, the following code in the Java Programming Language for reversing an array.

    Here, we define a function "reverse () " and pass an argument in its parameter i. e., an integer type array variable "arr1[]" inside it. we set two integer type variables i. e., "x" and "num" stores length of an array. Finally, set the for loop for reversing an array which starts from 0 and end at the length of an array.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definition of a method reverse, whose parameter is an array of integers. The method reverses the elements of the array. The ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers