Computer Science, asked by mohantalinky9894, 10 months ago

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.

Answers

Answered by gulharabegum
0

Explanation:

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

SOLUTION:

?

public void reverse ( int[] a )

{

for ( int i = 0 ; i < a.length/2 ; i++ )

{

int temp = a[i] ;

a[i] = a[a.length-i-1] ;

a[a.length-i-1] = temp ;

}

}

Similar questions