You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
432 B

  1. import java.util.Arrays;
  2. public class ArrayManipulation {
  3. public static void main(String[] args) {
  4. int[] arr = { 1, 2, 3, 4, 5 };
  5. System.out.println(Arrays.toString(reverseArray(arr)));
  6. }
  7. public static int[] reverseArray(int[] arr) {
  8. for (int i = 0; i < arr.length / 2; i++) {
  9. int tmp = arr[i];
  10. arr[i] = arr[arr.length - 1 - i];
  11. arr[arr.length - 1 - i] = tmp;
  12. }
  13. return arr;
  14. }
  15. }