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.

25 lines
724 B

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