Ask Question
2 May, 19:13

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

+3
Answers (1)
  1. 2 May, 19:43
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers