Answer:
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;
}
}
Step-by-step 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.